2

I have a basic setup for a Websocket Stomp Client. The problem is that the StompSubProtocolHandler, WebsocketInboundChannelAdapter and the WebsocketOutboundMessageHandler treat messages as if the application is a server.

The messages get special treatment depending on whether they are inbound or outbound.

For example, I send a message through the outbound-channel-adapter with simpMessageType="CONNECT" and the StompSubProtocolHandler's handleMessageToClient [thankfully] does not do what it is supposed to do with a CONNECT message because it does not expect such a message to be sent.

Then a CONNECTED [CONNECT_ACT] message comes back and is handled by the StompSubProtcolHandler's handleMessageFromClient function. This function doesn't know what to do with this CONNECTED frame and instead of publishEvent it attempts to send the message to the outputChannel. This would be ok except that the WebsocketInboundChannelAdapter is aware of simpMessageTypes and ignores the message because it is not a "MESSAGE" type.

I feel like there must be some kind of client side websocket channel adapters that I don't know about. I also feel like there must be some kind of StompSubProtocolHandler that is designed with the client in mind as well. There are not a lot of examples applications using the int-websocket:client-container and I am at a loss of what to do.

Can anybody please help me understand what I need to do to handle STOMP messages as a websocket client?

<int-websocket:client-container id="websocketClientContainer"
                                client="websocketStompClient" 
                                uri="ws://localhost:8080/stomp" />

<bean id="stompSubProtocolHandler"
      class="org.springframework.web.socket.messaging.StompSubProtocolHandler"/>

<int-websocket:inbound-channel-adapter 
             channel="receiveMessage"
             container="websocketClientContainer"
             default-protocol-handler="stompSubProtocolHandler"/>

<int:channel id="receiveMessage" />

<int:service-activator ref="websocketStompClient" 
         method="receiveNotification" 
         input-channel="receiveMessage" 
         output-channel="nullChannel" />

<int-event:inbound-channel-adapter 
      event-types="org.springframework.web.socket.messaging.AbstractSubProtocolEvent"
      payload-expression="message"
      channel="routeStompEvents"/>

<int:channel id="routeStompEvents" />

<int:router ref="StompInboundMessageTypeRouter"
                method="routeStompMessage"
                input-channel="routeStompEvents" 
                default-output-channel="nullChannel" 
                resolution-required="false" />

2 Answers2

1

Spring-WebSockets doesn't currently have client support so we're currently limited to supporting the server-side.

However, it's just been committed to master (last week) and will be in Spring 4.2. We will also add the appropriate support to Spring Integration 4.2.

The JIRA issue has a link to the commit, with tests etc.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Does spring-integration support the stomp client now? Is there any working example or any documentation on how to do this? – raiyan Feb 23 '17 at 05:57
  • *stomp client over weboscket, not just stomp client – raiyan Feb 23 '17 at 06:34
  • 1
    Yes; see [the documentation](http://docs.spring.io/spring-integration/reference/html/stomp.html)... `To configure STOMP ... let’s start with the STOMP Client object. The Spring Framework provides these implementations: ...` – Gary Russell Feb 23 '17 at 13:54
  • Oh! I went through the documentation before . I skipped the first part and thought it only supported tcp this whole time. Thanks for the prompt reply! – raiyan Feb 23 '17 at 14:07
0

Well, what I want to confirm that CONNECT as a message to the <int-websocet:outbound-channel-adapter> from the client side works well.

We have just missed to handle StompCommand.CONNECTED in the WebSocketInboundChannelAdapter from client side, which looks like should be emitted as a SessionConnectedEvent as a confirmation from the server.

Another missed STOMP Frame is StompCommand.RECEIPT, which should be emitted like some new StompReceiptEvent.

Feel free to raise a JIRA issue on the matter, and we'll take a look to the stomp-chat afterwards to add the Java Client as well.

More smooth integration with STOPM as Client we can address with some new int-stopm components.

UPDATE

The JIRA on the matter: https://jira.spring.io/browse/INT-3686 To fully support STOMP protocol with adapters we have another ticket: https://jira.spring.io/browse/INT-3685

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118