Question
Question

Reputation: 35

Message format in Message broker

I am new to message brokers and I am trying to run a simple project which sends a message "Hello" to the broker. The message broker is ActiveMQ.

using System;
using Amqp;

namespace Sender
{
    class Program
    {
        static void Main(string[] args)
        {
            Address address = new Address("amqp://guest:guest@localhost:5672");
            Connection connection = new Connection(address);
            Session session = new Session(connection);

            Message message = new Message("Hello");
            SenderLink sender = new SenderLink(session, "sender-link","test");
            sender.Send(message);


            sender.Close();
            session.Close();
            connection.Close();
        }
    }
}

But when I see the message in the web console of the ActiveMQ it shows the message details as "Sw¡Hello". I don't see why it is printing some extra characters. Can someone please help me with this?

Upvotes: 0

Views: 786

Answers (2)

Justin Bertram
Justin Bertram

Reputation: 34988

As far as the broker is concerned, the body of any message is just an array of bytes. Those bytes could be binary data or text data. If it is text the characters could be encoded with US-ASCII, UTF-8, UTF-16, etc. The broker doesn't know and doesn't care.

The web console does its best to print the data for administrative purposes, but it can't always get everything right which is almost certainly why you're seeing odd characters.

The real way to check the data in the message is to actually consume it and verify its contents that way.

Upvotes: 0

Tim Bish
Tim Bish

Reputation: 18356

The layout in the ActiveMQ console for an AMQP message body can be a little off from what the real contents are as the message is converted to an intermediary form of the broker's own internal protocol called Openwire. As such you shouldn't count on seeing things perfectly formatted there as the broker may be preserving additional data needed to fully reconstruct the AMQP message or is could just be storing it as a raw bytes message which means the message body will have the UTF8 size encoding bytes retained in the body.

The more important thing to check is that if you consume the message using an AMQP client do you get the payload you were expecting.

The internal cross-coding of the message from AMQP to Openwire is controlled by the AMQP transformer that is configured, see the documentation here.

Upvotes: 1

Related Questions