Question

in our current app, we are using Spring AMQP this way:

<rabbit:connection-factory  id="cachingConnectionFactory" 
                            username="${rabbitmq.connection.username}"
                            password="${rabbitmq.connection.password}"
                            host="${rabbitmq.connection.host}" 
                            port="${rabbitmq.connection.port}"
                            executor="rabbitmqPoolTaskExecutor"
                            requested-heartbeat="${rabbitmq.connection.requested-heartbeat}"
                            channel-cache-size="${rabbitmq.connection.channel-cache-size}"
                            virtual-host="${rabbitmq.connection.virtual-host}" />

<rabbit:admin   id="adminRabbit" 
                connection-factory="cachingConnectionFactory"
                auto-startup="true" />

<rabbit:template    id="rabbitTemplate"
                    connection-factory="cachingConnectionFactory"
                    exchange="v1.general.exchange"
                    message-converter="jsonMessageConverter" 
                    encoding="${rabbitmq.template.encoding}"
                    channel-transacted="${rabbitmq.template.channel-transacted}" />

<rabbit:queue id="v1.queue.1" name="v1.queue.1"  />
<rabbit:queue id="v1.queue.2" name="v1.queue.2" />
<rabbit:queue id="v1.queue.3" name="v1.queue.3" />

<fanout-exchange name="v1.general.exchange" xmlns="http://www.springframework.org/schema/rabbit" >
    <bindings>
        <binding queue="v1.queue.1" />
        <binding queue="v1.queue.2" />
        <binding queue="v1.queue.3" />
    </bindings>
</fanout-exchange>

<listener-container xmlns="http://www.springframework.org/schema/rabbit"
                    connection-factory="cachingConnectionFactory" 
                    message-converter="jsonMessageConverter" 
                    task-executor="rabbitmqPoolTaskExecutor"
                    auto-startup="${rabbitmq.listener-container.auto-startup}"
                    concurrency="${rabbitmq.listener-container.concurrency}"
                    channel-transacted="${rabbitmq.listener-container.channel-transacted}"
                    prefetch="${rabbitmq.listener-container.prefetch}"
                    transaction-size="${rabbitmq.listener-container.transaction-size}" >

    <listener id="v1.listener.queue.1" ref="listener1" method="handleMessage" queues="v1.queue.1" />
    <listener id="v1.listener.queue.2" ref="listener2" method="handleMessage" queues="v1.queue.2" />
    <listener id="v1.listener.queue.3" ref="listener3" method="handleMessage" queues="v1.queue.3" />

</listener-container>

<bean id="amqpServerConnection" class="com.sub1.sub2.RabbitGatewayConnectionImpl">
    <property name="rabbitTemplate" ref="rabbitTemplate" />
</bean>

When I am configuring the websocket in the new Spring 4-based app I don't know how/where declare exchanges, queues, etc...

registry.enableStompBrokerRelay("/example1/", "/example2/")
            .setApplicationLogin("guest")
            .setApplicationPasscode("guest")
            .setAutoStartup(true)
            .setRelayHost("localhost")
            .setRelayPort(5672)
            .setSystemHeartbeatReceiveInterval(10000)
            .setSystemHeartbeatSendInterval(10000);

This stuff must be implement with AMPQ yet?

Était-ce utile?

La solution

Essentially clients establish a WebSocket session and use STOMP for messaging (STOMP over WebSocket), not AMQP. In STOMP everything is driven by the destination header and it's up to message brokers to define what it means. For example, check the RabbitMQ STOMP plugin page to see how Rabbit maps STOMP destinations to queues and exchanges.

So if you think of RabbitMQ as your message broker where you already manage queues, exchanges, etc. On the web application side, the messaging protocol is STOMP, clients can send messages to STOMP destinations mapped to @MessageMapping controller methods or to destinations supported by RabbitMQ. Furthermore, controllers, or any other component injected with a SimpMessagingTemplate can send messages to the broker (Rabbit) which will then broadcast to connected web clients.

Hope this helps.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top