0

Was trying out RSocket Request/Response as specified in section 4 of https://www.baeldung.com/spring-boot-rsocket. So there is a RSocketServer autoconfigured and listening at port 7000. Unable to connect to the method annotated with @GetMapping when hitting the same from browser

@RestController
public class MarketDataRestController {

    private final RSocketRequester rSocketRequester;

    public MarketDataRestController(RSocketRequester rSocketRequester) {
        this.rSocketRequester = rSocketRequester;
    }

    @GetMapping(value = "/current/{stock}")
    public Publisher<MarketData> current(@PathVariable("stock") String stock) {
        return rSocketRequester
          .route("currentMarketData")
          .data(new MarketDataRequest(stock))
          .retrieveMono(MarketData.class);
    }
}

Expecting to be able to connect to the current() of the class MarketDataRestController annotated with @GetMapping when requesting the same from browser, say e.g.: http://localhost:7000/current/APPLE. Not sure how to connect to the same.

Emily
  • 1,030
  • 1
  • 12
  • 20
tux
  • 36
  • 3

1 Answers1

2

You can't use @RequestMapping with sockets, use @MessageMapping instead:

instead of @RequestMapping or @GetMapping annotations like in Spring MVC, we will use the @MessageMapping annotation:

@Controller
public class MarketDataRSocketController {
private final MarketDataRepository marketDataRepository;
public MarketDataRSocketController(MarketDataRepository marketDataRepository) {
    this.marketDataRepository = marketDataRepository;
}
@MessageMapping("currentMarketData")
public Mono<MarketData> currentMarketData(MarketDataRequest marketDataRequest) {
    return marketDataRepository.getOne(marketDataRequest.getStock());
}
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Thanks for the reply. My understanding is that the MessageMapping handler method currentMarketData() in MarketDataRSocketController is expected to be called from current() in MarketDataRestController. Please correct me if I am wrong. – tux Nov 03 '19 at 09:07
  • Separated out the REST client to a web-app of it's own and invoked the @MessageMapping handler method in the RSocket Server, but getting org.springframework.messaging.MessageDeliveryException: No handler for destination '' – tux Nov 03 '19 at 12:06
  • 1
    The above mentioned issue was resolved by the usage of RSocketRequester.Builder to obtain a RSocketRequester as mentioned in https://docs.spring.io/spring-boot/docs/2.2.0.M6/reference/html/spring-boot-features.html#boot-features-rsocket-requester . Thanks to Trisha Gee for commenting the same in https://stackoverflow.com/questions/57426578/rsocket-server-exception-no-handler-for-destination-destination-does-not-pa – tux Nov 03 '19 at 17:14