Skip to main content
Solved

Sending data using Websocket


mygis
Contributor
Forum|alt.badge.img+12
  • Contributor

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.

View original
Did this help you find an answer to your question?

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
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • 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
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • July 17, 2020
afavaccio wrote:

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+34
mygis wrote:

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
Contributor
Forum|alt.badge.img+12
  • Author
  • Contributor
  • July 17, 2020
virtualcitymatt wrote:

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
Contributor
Forum|alt.badge.img+19
  • Contributor
  • July 17, 2020
mygis wrote:

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
mygis wrote:

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings