Pushing N messages as JSON object in single queue.push{} call

It is very simple to push multiple messages onto the queue as a single JSON object.

  1. Create an array of messages
  2. Serialize it as JSON
  3. Push the serialized JSON onto the queue

This is how to encode the messages:

This is what the encoded JSON message looks like:

This is how to decode the messages:

Note: We encoded the messages into JSON in a From Translator. Then we used the encoded JSON message as sample data, in a To Translator, to test the decoding.

Here is the code that you can copy:

Encoding:

function main(Data)
   local Messages = {}
   Messages[1] = 'My first message'
   Messages[2] = 'My second message'
   queue.push{data=json.serialize{data=Messages}}
end

Decoding:

function main(Data)
   local Messages = json.parse{data=Data}
   for i = 1, #Messages do
      -- do something with Messages[i]
      trace(Messages[i])
   end
end

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.