Jetty websocket客户端连接到Stomp.js主题频道

时间:2015-07-08 12:25:23

标签: websocket client jetty spring-websocket

我编写了一个Spring Websocket服务器,可以通过Stomp.js从浏览器中进行评估。我现在正在尝试实现Java客户端,以便将我的服务器连接到辅助系统。我可以使用以下代码连接到服务器

String destUri = "ws://localhost:8080/sample";
    WebSocketClient client = new WebSocketClient();
    SimpleEchoSocket socket = new SimpleEchoSocket();
    try {
        client.start();
        URI echoUri = new URI(destUri);
        ClientUpgradeRequest request = new ClientUpgradeRequest();
        client.connect(socket, echoUri, request);
        System.out.printf("Connecting to : %s%n", echoUri);
        socket.awaitClose(5, TimeUnit.SECONDS);
    } catch (Throwable t) {
        t.printStackTrace();
}

连接已打开,现在我想连接到我的主题/价格流。这是通过stomp.js实现的:

stompClient.subscribe('/topic/pricechannel1', renderPrice);

我的Jetty websocket客户端的等效订阅方法是什么?我在网上找到的文档中找不到任何内容。

其他信息:

我正在尝试将stockticker示例found here实现到另一个项目中。我可以通过Web浏览器中提供的Stomp.js interface连接到服务器。现在我正在尝试创建一个Java客户端,以便在Swing GUI中使用Jetty websocket-client进行连接。

我需要连接到价格流,但似乎我缺少某种配置请求来锁定作为主题的目的地

1 个答案:

答案 0 :(得分:2)

In general, plain websocket clients (as the one provided by Jetty) support the websocket standard. STOMP is a protocol that sits on top of that transport.

Here, you'd need to implement your own STOMP client or interface an existing one with the websocket client you're using.

Spring 4.2 (to be published soon) includes a new STOMP client for this particular use case. See the reference documentation of 4.2.RC2.

相关问题