我从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();
有人可以帮我举个例子吗?
答案 0 :(得分:2)
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);