I'm using RabbitMQ and Spring Websockets for messages to be displayed on a webpage via STOMP. I'd like each web page to receive all messages sent to the exchange (fanout).
Messages are currently received on the webpage however the behaviour is like a queue (rather than fanout) in that if 2 web pages are open and 10 messages are added to the exchange then each web page receives 5 messages.
Does anyone know what config needs to be changed to use the fanout exchange?
Javascript
var socket = new WebSocket("ws://localhost:8080/messaging-example/portfolio/websocket");
var stompClient = Stomp.over(socket);
var headers = {};
var connectCallback = function(frame) {
stompClient.subscribe("/queue/testQueue", function(message) {
document.body.innerHTML += "<p>" + message + "</p>";
}, { });
};
var errorCallback = function(frame) {
console.log("Connection Error");
};
stompClient.connect(headers, connectCallback, errorCallback);
Spring
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/portfolio">
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:stomp-broker-relay
relay-host="x.x.x.x"
relay-port="61613"
system-login="user1"
system-passcode="password"
client-login="user1"
client-passcode="password"
prefix="/queue"/>
</websocket:message-broker>
RabbitMQ
"queues":[
{
"name":"testQueue",
"vhost":"/",
"durable":true,
"auto_delete":false,
"arguments":{
}
}
],
"exchanges":[
{
"name":"testExchange",
"vhost":"/",
"type":"fanout",
"durable":true,
"auto_delete":false,
"internal":false,
"arguments":{
}
}
],
"bindings":[
{
"source":"testExchange",
"vhost":"/",
"destination":"testQueue",
"destination_type":"queue",
"routing_key":"",
"arguments":{
}
}
]