英文:
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 "consumeNextWith" 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("wss://stream.binance.com:9443/ws"))
.block();
}
@Test
void shouldRetrieveStockPricesFromTheService() {
//when
final Flux<String> aggregatedTradeStream = requester
.route("/bnbbtc@aggTrade")
.retrieveFlux(String.class)
.take(1)
.doOnError(e -> log.error(e.toString()));
// then
StepVerifier.create(aggregatedTradeStream)
.consumeNextWith(response -> {
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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论