Reputation: 619
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?
Upvotes: 1
Views: 1149
Reputation: 13448
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/
Upvotes: 1