I am trying to configure web socket support in Spring 4 using RabbitMQ as the external broker, but as soon as I switch to RabbitMQ, I get the following error on start-up in the client:
'/user/queue/changes' is not a valid destination.
Valid destination types are: /temp-queue, /exchange, /topic, /queue, /amq/queue, /reply-queue/.
On the server I am using convertAndSendToUser
and this works fine with the simple broker, but as soon as I switch to RabbitMQ, I get this error. Note that RabbitMQ works fine for normal topic broadcasts - it's just the /user
channel that falls over.
Do I need to do something special to get /user
to work with RabbitMQ?
Edit to include Web Socket Config
My WebSocketConfig
is pretty standard with a few customisations to integrate it with spring-session:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer<ExpiringSession> {
@Override
public void configureStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/changes").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
//config.enableSimpleBroker("/queue", "/topic");
StompBrokerRelayRegistration r = config.enableStompBrokerRelay("/user", "/topic");
try {
String rabbitUrl = System.getenv("CLOUDAMQP_URL");
if(rabbitUrl != null) {
log.info("RABBIT URL detected: " + rabbitUrl);
URI uri = new URI(rabbitUrl);
String host = uri.getHost();
String login = uri.getUserInfo().split(":",2)[0];
String passCode = uri.getUserInfo().split(":",2)[1];
String vhost = uri.getPath().substring(1);
r.setRelayHost(host);
r.setSystemLogin(login);
r.setSystemPasscode(passCode);
r.setClientLogin(login);
r.setClientPasscode(passCode);
r.setVirtualHost(vhost);
}
} catch(Exception e) {
log.error("Error setting up RabbitMQ", e);
}
config.setApplicationDestinationPrefixes("/app");
}
}