Skip to main content

I am using a websocket to stream data from FME server (2018) to a web app in a browser. The data I am streaming out can be classified by its location, and the user of the web app only views one location at a time. So ideally the websocket stream id would be something like '<location>_data', where <location> is dynamic and set by the feature in the workspace.

This doesn't appear possible though. Setting up the workspace like this seems to instantiate the stream id of the websocket sender with the first feature to pass through it, and then fixes it for the remainder of the job. E.g. if location 'X' was the first feature to be processed, the stream id would be 'X_data' even when locations 'A', 'B' or 'C' passed through. Is this how the websocket sender works? Is there any workaround for this?

It is possible for me to stream all data for all locations out through a websocket with stream id 'data', however this is very wasteful, since the browser will download data for all locations and most of it will just fall on the floor, and the bandwidth will very quickly add up to be substantial.

It is also not really an option for me to set up individual websockets for each location. There may be ~200 locations present, and this can change dynamically.

Hi @cdog89

 

 

From my testing, it doesn't seem to work if you include attributes as values inside the text values for connection preamble or data to transmit, but what I have found that works:

 

 

In the Connection Preamble, open ALL streams for every location that you may be streaming data to.
{
   "ws_op"         : "open",
   "ws_stream_ids" :  "websocket1", "websocket2", "websocket3"]
}

 

 

For the Data To Transit you will need to do two things:

 

1. Generate this message in an AttributeCreator beforehand

2. In the message, you will need to specify which stream you're sending the data to, like this:

 

 

{
   "ws_op"  : "send",
   "ws_stream_id" : "@Value(websocket_stream)",
   "ws_msg" : "@Value(websocket_stream)"
}

 

 

To test this I set each stream to post to a different topic, and say which stream id they were connecting to and that seemed to work. Make sure you've set the right attribute in the WebsocketSender transformer.

 

0684Q00000ArL4HQAV.png


Hi @cdog89

 

 

From my testing, it doesn't seem to work if you include attributes as values inside the text values for connection preamble or data to transmit, but what I have found that works:

 

 

In the Connection Preamble, open ALL streams for every location that you may be streaming data to.
{
   "ws_op"         : "open",
   "ws_stream_ids" :  "websocket1", "websocket2", "websocket3"]
}

 

 

For the Data To Transit you will need to do two things:

 

1. Generate this message in an AttributeCreator beforehand

2. In the message, you will need to specify which stream you're sending the data to, like this:

 

 

{
   "ws_op"  : "send",
   "ws_stream_id" : "@Value(websocket_stream)",
   "ws_msg" : "@Value(websocket_stream)"
}

 

 

To test this I set each stream to post to a different topic, and say which stream id they were connecting to and that seemed to work. Make sure you've set the right attribute in the WebsocketSender transformer.

 

0684Q00000ArL4HQAV.png

@jlutherthomas Great, I think I can work with this. I guess it isn't truly dynamic, but for what I'm doing it will get the job done. Thanks a lot.


Reply