Search code examples
rabbitmqprotocol-buffersnservicebus

Decode RabbitMQ payload


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.


Solution

  • 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.