Skip to main content
Best Answer

Sending data using Websocket

  • July 16, 2020
  • 7 replies
  • 18 views

mygis
Supporter
Forum|alt.badge.img+14

Hi,

 

I am using the websocketSender transformer to stream some data; when I am using the template in the data to transmit as below:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : "FME Rocks"

 

}

 

I have no issues; however when replacing the "FME Rocks" with the attribute name, nothing happens. For example, if I have an attribute named "id", here is what I do:

{

 

"ws_op" : "send",

 

"ws_msg" : fme_get_attribute("id")

 

}

I don't get any errorr, it is just that data is not transmitted compared to the first case.

Any pointers would be much appreciated.

Thanks.

Lyes

 

 

 

Best answer by mygis

Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : @Value(id)

 

}

 

I can now transmit data successfully from one workspace to another.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

afavaccio
Forum|alt.badge.img+2
  • July 16, 2020

Hi @gisinnovationsb,

 

 

you can try this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : ("id")

 

}

 

 

or this:

 

 

{

 

ws_op: 'send',

 

ws_msg: '@Value(id)'

 

}

 

 

HTH

Andrea


mygis
Supporter
Forum|alt.badge.img+14
  • Author
  • Supporter
  • Best Answer
  • July 17, 2020

Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : @Value(id)

 

}

 

I can now transmit data successfully from one workspace to another.


mygis
Supporter
Forum|alt.badge.img+14
  • Author
  • Supporter
  • July 17, 2020

Hi @gisinnovationsb,

 

 

you can try this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : ("id")

 

}

 

 

or this:

 

 

{

 

ws_op: 'send',

 

ws_msg: '@Value(id)'

 

}

 

 

HTH

Andrea

Hi @afavaccio both didn't work. I found the solution please refer to my reply and thanks for the help.


virtualcitymatt
Celebrity
Forum|alt.badge.img+47

Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : @Value(id)

 

}

 

I can now transmit data successfully from one workspace to another.

Haha, gosh very sensitive to the syntax. Not what I'm used to with FME. Thanks for sharing your results.


mygis
Supporter
Forum|alt.badge.img+14
  • Author
  • Supporter
  • July 17, 2020

Haha, gosh very sensitive to the syntax. Not what I'm used to with FME. Thanks for sharing your results.

Hi Matt, I will accept your comment as the response ;)


takashi
Celebrity
  • July 17, 2020

Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

   {

 

       "ws_op"  : "send",

 

        "ws_msg" : @Value(id)

 

    }

 

I can now transmit data successfully from one workspace to another.

I think the data to transmit should be a valid JSON text.

If id was a numeric value - e.g. 100, your expression would be a valid JSON. 

{
"ws_op" : "send",
"ws_msg" : 100
}

 

However, if id was a non-numeric value - e.g. ABC, the expression wouldn't be a valid JSON.

{
"ws_op" : "send",
"ws_msg" : ABC
}

 

In the case, the id should be quoted with double quotations, as in.

{
"ws_op" : "send",
"ws_msg" : "ABC"
}

Forum|alt.badge.img+1
  • July 17, 2020

Hi, I created the string using the AttributeCreator then assigned the created string to Data to Transmit. The result was something like this:

 

 

{

 

"ws_op" : "send",

 

"ws_msg" : @Value(id)

 

}

 

I can now transmit data successfully from one workspace to another.

I had a similar issue. The explanation that I got in https://knowledge.safe.com/questions/98505/send-json-via-websocket.html from @denniswilhelm (which I've verified too) is: "fme_get_attribute automatically escapes " to \\" which isn't done by the @Value command. In a JSONTemplater you can also use fme:get-json-attribute("yourAttributeName") to explicitly load insert valid JSON values."

 

Hence the difference between the two, seemingly, identical ways to get data from the attribute.