Decode RabbitMQ payload
Asked Answered
Z

2

6

In our team, we exchange messages via RabbitMQ between two systems. The messages are encoded in protobuf (v3). We use NServiceBus on the sending and receiving side. We use the RabbitMQ management UI for monitoring the error queue. In production, we noticed that it is not easy to make sense of the payload of the messages in the error queue, which are base64-encoded.

What is the easiest way to get human-readable access to the messages in the error queue? We have full control over the decisions in both systems, and also discussed a switch to JSON-encoded messages (instead of protobuf). But we are otherwise happy with our protobuf-based implementation. Which is already implemented after all.

Ziegfeld answered 8/7, 2019 at 18:8 Comment(0)
D
3

Protobuf v3 supports formatting as json, once you have the data parsed as IMessage (the base type for in-memory protobuf objects).

So you can convert a single message to be human readable as follows:

  • Use the webUI GetMessage function to get the message as base64 then requeue it
  • Convert the message back to protobuf binary via Convert.FromBase64String
  • Parse it back to an IMessage via ProtoMessageTypeGoesHere.Parser.ParseFrom(binaryData)

You can then convert the parsed message to Json via ToString() or Google.Protobuf.JsonFormatter.

As long as your error queue isn't going to be disrupted by the re-queuing (e.g. resetting of timestamps or reprocessing), you should be able to do this for all messages in the queue.

Dub answered 22/7, 2019 at 13:0 Comment(2)
what is the name of the tool to run the functions mentioned in this answer, please?Selfsown
To get the message contents I used the port 15672 web ui (other options here). The other steps were using the .NET protobuf library (question is tagged with NServiceBus which is .NET).Dub
B
0

I wouldn't recommend using the management UI for this. A simple script or html page with a stomp client would be a lot easier to use and more error-proof, in my opinion.

However, to answer your question: to simply decode the message and replace the text, a simple javascript solution will work fine.

$(".msg-payload").text(atob($(".msg-payload").text()))

This will simply select the message field on the queue page on the RabbitMQ management UI and replace it with the decoded value (that's the function atob).

To use this, you can either run it from the console or add it as a bookmark in your browser. Simply use the code prefixed with javascript:, like so:

javascript:$(".msg-payload").text(atob($(".msg-payload").text()))
Brigham answered 17/7, 2019 at 18:54 Comment(1)
This just converts from base64 to binary, for a protobuf message this will look something like ����..Dub

© 2022 - 2024 — McMap. All rights reserved.