【问题标题】:How can I add custom properties to a message with Apache.NMS.ActiveMQ (C#)?如何使用 Apache.NMS.ActiveMQ (C#) 向消息添加自定义属性?
【发布时间】:2015-01-23 12:37:22
【问题描述】:

我从 C# 中的 ActiveMQ 开始。 我将我的对象序列化为 json 并毫无问题地发送它。

我会在消息中添加属性,但没有成功。我在少数网站上看到过 setIntProperty(String name,int value),但在 Apache.NMS.ActiveMQ (C#) 上找不到。

这是我的代码:

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();

谁能帮我举个例子吗?

【问题讨论】:

    标签: c# jms activemq apache-nms


    【解决方案1】:

    ITextMessage 继承自 IMessage,它有一个 map of Properties, with several applicable set methods。在发送之前,您应该可以如下设置:

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

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 2012-03-01
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 2015-03-09
      相关资源
      最近更新 更多