How can I add custom properties to a message with Apache.NMS.ActiveMQ (C#)?

3.9k views Asked by At

I am starting with ActiveMQ in C#. I serialize my object to json and send it without problem.

I would add properties to my message but I don't succeed. I have seen the setIntProperty(String name,int value) on few websites but I don't find it on Apache.NMS.ActiveMQ (C#).

Here my code :

ActiveMQ mom = new ActiveMQ();
ISession session = mom.Initialize();
IDestination dest = session.GetQueue(queueDestination);
using (IMessageProducer producer = session.CreateProducer(dest))
{
    foreach (Store s in stores)
    {
        List<string> matchKeyProductList = db.GetProductsKeyList(websiteNumberID);
        ArrayList arCodesProdToUpdate = db.GetProductsToUpdate(websiteNumberID);

        JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
        serializer.MaxJsonLength = Int32.MaxValue; //Augmentation de la propriété MaxJsonLenth
        MessageObject message = new MessageObject(matchKeyProductList, arCodesProdToUpdate);
        string jsonMessage = serializer.Serialize(message);

        ITextMessage textMessage = producer.CreateTextMessage(jsonMessage);
        producer.Send(textMessage);
    }
}
mom.Cleanup();

Can anyone help me with an example, please ?

1

There are 1 answers

0
StuartLC On BEST ANSWER

ITextMessage inherits from IMessage, which has a map of Properties, with several applicable set methods. You should be able to set these as follows, before sending:

ITextMessage textMessage = producer.CreateTextMessage(jsonMessage);
textMessage.Properties.SetInt("CustomInt", 1234);
textMessage.Properties.SetString("CustomString", "HelloWorld");
producer.Send(textMessage);