使用spring4 stomp和socksjs应用程序配置rabbitmq

时间:2014-10-19 14:12:23

标签: rabbitmq stomp sockjs spring-4

我遇到了春季4 + Stomp + socks js app的问题。它与简单的消息代理正常工作但是当切换到rabbitmq时它无法正常工作,并且无法解决它与提到的答案 Configure External Broker(RabbitMQ) In Spring4+STOMP+SockJS Application

我的代码是:

<websocket:message-broker application-destination-prefix="/app">
    <websocket:stomp-endpoint path="/hello">
        <websocket:sockjs/>
    </websocket:stomp-endpoint>
    <websocket:stomp-broker-relay prefix="/topic" system-login="guest" system-passcode="guest" client-login="guest"
                                  client-passcode="guest" relay-host="localhost" relay-port="15672"/>
</websocket:message-broker>

控制器:

    @Controller
public class StompController {

    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greetUser(User user) throws Exception {
        Thread.sleep(3000); // simulated delay
        return new Greeting("Hello, " + user.getName() + "!");
    }



}

JS:

function connect() {
            var socket = new SockJS('/hello');
            stompClient = Stomp.over(socket);
            stompClient.connect('guest','guest', function(frame) {
                setConnected(true);
                console.log('Connected: ' + frame);
                stompClient.subscribe('/topic/greetings', function(greeting){
                    showGreeting(JSON.parse(greeting.body).content);
                });
            });
        }

连接时说:

  

SEVERE [clientInboundChannel-1] org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.handleMessageInternal 消息代理未激活。忽略:[Payload byte [0]] [Headers = {stompCommand = CONNECT,stompCredentials = [PROTECTED],nativeHeaders = {heart-beat = [10000,10000],passcode = [PROTECTED],login = [guest],accept-version = [1.1,1.0]},simpMessageType = CONNECT,simpSessionAttributes = {},simpSessionId = ih_04mxa,id = d36fc1c1-e00c-fb48-51af-c526e3018e20,timestamp = 1413617272621}]

我甚至在兔子mq中启用了stomp插件。

1 个答案:

答案 0 :(得分:2)

STOMP端口

我认为Spring无法连接到您的RabbitMQ实例,因为您将其指向端口15672,我认为它必须是Web UI的默认端口或其他内容。 The default port for the STOMP connector with rabbitMQ is 61613(事实上这是the default value chosen by Spring)。你可以试试那个吗?

访问控制

此外,您一定要考虑您的访问控制配置as the guest user won't work remotely