Spring中的STOMP WebSocket在连接之前丢失了连接

时间:2016-08-20 08:46:56

标签: java spring websocket stomp

我尝试通过STOMP与服务器连接,但是我收到了带有任何特定信息的Lost Connection消息。

WebSocket配置:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableStompBrokerRelay("/topic", "/queve")
            .setClientLogin("quest")
            .setClientPasscode("quest");
        registry.setApplicationDestinationPrefixes("/app");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/hello").setAllowedOrigins("*").withSockJS();
    }

}

控制器:

@Controller
public class HelloController {


    @MessageMapping("/hello")
    public void greeting(HelloMessage message){
        System.out.println("Wiadomosc: " + message.getName());
    }

    @SubscribeMapping({"/helloSub"})
    public HelloMessage handleSubscription() {
        HelloMessage outgoing = new HelloMessage();
        System.out.println("SUB");
        outgoing.setName("Jas");
        return outgoing;
    }

}

js script:

 var sock = new SockJS("http://localhost:8080/BuyMyTime/hello");
    var stomp = Stomp.over(sock);
    var payload = JSON.stringify({'name':'Jasiek'});
    stomp.connect('quest', 'quest', function(frame){
        //stomp.send("/hello", {}, payload);
    });

当我发送获得http://localhost:8080/BuyMyTime/hello时,我收到:欢迎来到SockJS!所以Socket很好,但是当我尝试stomp.connect时,我会收到:

Opening Web Socket... stomp.js:134:99
Web Socket Opened... stomp.js:134:99
>>> CONNECT
login:quest
passcode:quest
accept-version:1.1,1.0
heart-beat:10000,10000

"Whoops! Lost connection to http://localhost:8080/BuyMyTime/hello" stomp.js:134:99 

是否有任何丢失的配置我没有包括在内?如何获得有关此连接丢失的更多信息?请提供任何帮助。

更新(2016年8月28日)

我添加了这个依赖项:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.5.1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.5.1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.5.1</version>
</dependency>

现在得到:

<<< ERROR
message:Broker not available.
content-length:0
"Whoops! Lost connection to http://localhost:8080/BuyMyTime/greeting"

0 个答案:

没有答案