RSocket Java客户端,用于访问Binance的WebSocket API。

huangapple go评论70阅读模式
英文:

RSocket Java Client to access Binance websocket API

问题

以下是翻译好的内容:

我正在尝试使用Spring的RSocket连接到Binance的WebSocket端点,但是我遇到了以下异常。

java.lang.AssertionError: 期望 "consumeNextWith" 失败(期望: onNext(); 实际: onError(java.nio.channels.ClosedChannelException))

以下是我的测试代码:

@SpringBootTest
@Slf4j
class RSocketClientIntegrationTest {

    private static RSocketRequester requester;

    @BeforeAll
    public static void setupOnce(@Autowired RSocketRequester.Builder builder) {
        // 给定
        requester = builder
                .connectWebSocket(URI.create("wss://stream.binance.com:9443/ws"))
                .block();
    }

    @Test
    void shouldRetrieveStockPricesFromTheService() {
        // 当
        final Flux<String> aggregatedTradeStream = requester
                .route("/bnbbtc@aggTrade")
                .retrieveFlux(String.class)
                .take(1)
                .doOnError(e -> log.error(e.toString()));

        // 那么
        StepVerifier.create(aggregatedTradeStream)
                .consumeNextWith(response -> {
                    assertThat(response).isNotNull();
                })
                .verifyComplete();
    }
}

我能否直接连接到WebSocket端点,使用RSocket,还是必须创建一个处理WebSocket的RSocket服务器,然后从这个代理服务器连接到WebSocket?

英文:

I am trying to connect to Binance websocket endpoint using RSocket with Spring, but I am getting the following exception.

java.lang.AssertionError: expectation &quot;consumeNextWith&quot; failed (expected: onNext(); actual: onError(java.nio.channels.ClosedChannelException))

Here is my testing code:

@SpringBootTest
@Slf4j
class RSocketClientIntegrationTest {

    private static RSocketRequester requester;

    @BeforeAll
    public static void setupOnce(@Autowired RSocketRequester.Builder builder) {
        // given
        requester = builder
                .connectWebSocket(URI.create(&quot;wss://stream.binance.com:9443/ws&quot;))
                .block();
    }

    @Test
    void shouldRetrieveStockPricesFromTheService() {
        //when
        final Flux&lt;String&gt; aggregatedTradeStream = requester
                .route(&quot;/bnbbtc@aggTrade&quot;)
                .retrieveFlux(String.class)
                .take(1)
                .doOnError(e -&gt; log.error(e.toString()));

        // then
        StepVerifier.create(aggregatedTradeStream)
                .consumeNextWith(response -&gt; {
                    assertThat(response).isNotNull();
                })
                .verifyComplete();
    }
}

Can I connect straight into a WebSocket endpoint using RSocket or do I have to create a RSocket server that handles the websocket and then from this proxy server I connect to the websocket?

答案1

得分: 1

RSocket over WebSocket使用WebSocket作为传输载体来承载RSocket数据。因此,您不能连接到原始WebSocket并期望任何工作。

尝试将上述程序与类似的端点进行测试:

wss://rsocket-demo.herokuapp.com/rsocket

请参阅文档:https://rsocket-demo.herokuapp.com/

英文:

RSocket over WebSocket uses websocket as a transport to carry RSocket payloads. So you can't connect to a raw WebSocket and expect anything to work.

Try testing the above program against an endpoint like

wss://rsocket-demo.herokuapp.com/rsocket

See docs at https://rsocket-demo.herokuapp.com/

huangapple
  • 本文由 发表于 2020年9月9日 19:13:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/63810466.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定