0

I want to exchange messages by web sockets between 2 java apps.

I have the following server configuration:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.setApplicationDestinationPrefixes("/app");
        registry.enableSimpleBroker("/queue", "/topic");
        registry.setUserDestinationPrefix("/user");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //todo remove handshake handler when authorization is implemented
        registry.addEndpoint("/ws").setAllowedOrigins("*").setHandshakeHandler(new TestHandshakeHandler()).withSockJS();
    }
}

and inside class marked with @Controller I have wrote following theme:

@MessageMapping("/consumer/client/add")
public void addClientRequest(String msgReq) {
    logger.info(msgReq);
}

and inside clien I do connect and in sime bean I wrote following:

@Autowired
private SimpMessagingTemplate simpMessagingTemplate;
...
simpMessagingTemplate.convertAndSend("/app/consumer/client/add", new StubObject("message"));

But after sending from client method addClientRequest doesn't invoke.

Please advice ways to troubleshot this issue.

Actually I don't understand issue. Maybe I send to wrong destination or I have issue with configuration or path is wrong or something else.

P.S.

I know that I can extend StompSessionHandlerAdapter

and obtain session from there but looks like it is the bad style and should be another way to achieve it

P.S.2

Inside class WebSocketTcpConnectionHandlerAdapter(inner class inside WebSocketStompClient) I see private volatile WebSocketSession session;

I want to obtain this object to send messages

JIST
  • 1,139
  • 2
  • 8
  • 30
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

0

I don't think it was designed to be used like this.

I think you must use a specific websocket client. This one for exemple : http://www.programmingforliving.com/2013/08/jsr-356-java-api-for-websocket-client-api.html

This code :

@MessageMapping("/consumer/client/add")
public void addClientRequest(String msgReq) {
    logger.info(msgReq);
}

Will NOT connect to a websocket client and wait to have messages. It expect a client to connect throught it and send messages.

Oreste Viron
  • 3,592
  • 3
  • 22
  • 34