C#使用NMS与ActiveMQ通讯问题总结:如何生成Stomp.js中的headers对象

在html5中使用Stomp.js与ActiveMQ通讯时,可以借助headers对象进行一些特殊的约定,例如:

//发送消息时,可以携带一个Headers对象
            var hds ={
              "name":"测试",
              "msg" :"测试头部发送"
            }
            client.send(destination, hds, text);

那么,在C# 中如何实现这个功能呢? 其实很简单,使用ITextMessage中的Properties属性就可以了,如下:

 ITextMessage msg = prod.CreateTextMessage();
                        msg.Text = this.textBox1.Text;
                        msg.Properties.SetString("name", "测试");
                        msg.Properties.SetString("msg", "哈哈哈哈");
                        prod.Send(msg, Apache.NMS.MsgDeliveryMode.Persistent, Apache.NMS.MsgPriority.Normal, new TimeSpan(TimeSpan.TicksPerMillisecond * 10));

使用浏览器接收C#发布的消息,在控制台中即可看到Properties定义的参数


你可能感兴趣的:(C#)