kamilfb / mqtt-spy

Please use the new Eclipse Paho GitHub repo instead.
https://github.com/eclipse/paho.mqtt-spy/wiki
346 stars 68 forks source link

Formatter execution consistency #100

Closed NicolSpies closed 8 years ago

NicolSpies commented 8 years ago

Hi Kamil,

My message payload is in JSON but I need it in XML. I use the following code in the formatter inline script to transform the JSON to XML:

function format() { xml = "<payload>" + json2xml(receivedMessage.getPayload()) + "</payload>"; receivedMessage.setPayload(xml); return xml; }

where the json2xml() function does the formatting successfully. The format function set the received message payload to the xml transformed message and also returns it to the message box on the GUI.

The transformed message is displayed as XML in the GUI 100% of the time indicating the transformation from JSON to XML is correct every time BUT sometimes even though the xml is returned by the format function correctly, the receivedMessage.setPayload(xml) function does not save the message as xml but still as the original JSON.

I am simultaneously running another version of mqtt-spy on another PC receiving the same messages. It happens there as well but at different times on different messages.

The frequency is 50 incorrect payload sets out of 570 messages over a period of 4 days with no apparent pattern in payload and time of occurrence.

The only thing I can think of is that it might be timing related. The only other info that might be of value is that every message is entered in the log file is duplicated with similar id's and timestamps. But in 91% of the time this does not cause a problem with the message payloads correctly transformed and saved in xml as done by the format function.

At the time when an incorrect message is entered into the messages log there are no accompanying entries entered into the application mqtt-spy.log file.

Any thoughts on the phenomena ?

kamilfb commented 8 years ago

Hi @NicolSpies. Thank you for reporting this. Have you tried doing this in the onMessage() function for the subscription as opposed to doing it in the formatter's format()? The formatter should be used purely for formatting messages in the GUI, the onMessage is more suited for modifying the message itself. Let me know if that resolves the problem.

kamilfb commented 8 years ago

@NicolSpies, if onMessage works fine now, is that still an issue? Please advise

NicolSpies commented 8 years ago

No issue anymore but maybe worth taking note of. thanks