I'm researching switching to WildFly 10 and, subsequently, Artemis. I've set up a simple Spring Websocket project, as described here: https://spring.io/guides/gs/messaging-stomp-websocket/. The meat of the project are WebSocketConfig:
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableStompBrokerRelay("/queue/", "/topic/");
config.setApplicationDestinationPrefixes("/app");
}
And controller:
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public Greeting greeting(HelloMessage message) throws Exception {
return new Greeting("Hello, " + message.getName() + "!");
}
This works like a charm as it is with ActiveMQ, no additional configuration required on the broker side.
Knowing that Artemis requires either a pre-created destination, or a specific mention of automatic queue creation, i added this to my broker.xml:
<address-setting match="#">
<dead-letter-address>jms.queue.DLQ</dead-letter-address>
<expiry-address>jms.queue.ExpiryQueue</expiry-address>
<redelivery-delay>0</redelivery-delay>
<max-size-bytes>10485760</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>BLOCK</address-full-policy>
<auto-create-jms-queues>true</auto-create-jms-queues>
</address-setting>
</address-settings>
However, this didn't work as i expected and broker still refused to create /queue/greetings
. So, i've researched a bit more and found that Artemis, in fact, likes queues to be names with jms.queue.*
prefix. I renamed my queue to jms.queue.greetings
and made the following changes to Spring code:
Configuration:
...
config.setPathMatcher(new AntPathMatcher("."));
...
Controller:
...
@SendTo("jms.queue.greetings")
...
To my understanding, this should have forced my controller to send messages to this queue. Broker liked this change and finally created the queue, but Spring controller on the other hand did not - no messages appear in jms.queue.greetings.
I can force my way around the issue by making code less pretty, subscribing to required queues with some hand-made injected services, but that way i will loose Spring sockJS magic - Artemis (unlike RabbitMQ) doesn't seem to provide http
endpoint to Stomp, and connecting to ws://
will just lead to CORS errors. No inbuilt CORS support either, it seems.
I will appreciate any thoughts on how i might overcome this issue.
EDIT: My JS looks like this:
var ws = new SockJS('/hello');
client = Stomp.over(ws);
...
client.connect(login, passcode, function(frame) {
client.debug("connected to Stomp");
....
client.subscribe('jms.queue.greetings', function(message) {
...
});
});
...
client.send("jms.queue.greetings", {}, JSON.stringify({ 'name': text }));
...