I want to create a REST service to turn on the light. The architecture that I want to have is the following:
- Many embedded system each is connected to one light instance
- Each embedded system has a websocket client, that connects to my server
- My server holds a REST service that allows webclients to choose one light instance, and turn it on
- The REST service would have a parameter to specify a reference for one light instance, connected to the system and send the message to websocket client, wait for an acknowledgement message from the client, and return the REST answer
I would like to accomplish this using Spring Integration framework. I was thinking of something like:
Request : Inbound HTTP GW -> Outbound Websocket GW
Response: Inbound HTTP GW <- Inbound Websocket GW
The problem is that I don't know how to specify the websocket client. Any idea how to do it ?
For now, and based on the answers I have received this is the pseudo-code that provides the solution:
<!-- REST service to turn on the light -->
<int-http:inbound-gateway
supported-methods="POST"
request-channel="lightOnRequest"
reply-channel="lightOnResponse"
path="rest/lighton/{sessionId}">
<int-http:header name="{sessionId}" expression="{sessionId}"/>
</int-http:inbound-gateway>
<!-- We add a header SESSION_ID_HEADER to choose the websocket destination client -->
<int:header-enricher
input-channel="lightOnRequest"
output-channel="lightOnClientRequest">
<int:header
name="#{T(...SimpMessageHeaderAccessor).SESSION_ID_HEADER}"
expression="headers.sessionId"/>
<int:header-channels-to-string/>
</int:header-enricher>
<!-- Websocket out to client -->
<int-websocket:outbound-channel-adapter
channel="lightOnClientRequest"
container="serverWebSocketContainer" />
<!-- Response reception from the Websocket client -->
<int-websocket:inbound-channel-adapter
channel="lightOnClientResponse"
container="serverWebSocketContainer" />
<!-- The websocket client provides again the reply channel in the headers.
The bridge connects the response to the reply channel -->
<int:bridge input-channel="lightOnClientResponse"/>