在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定義的參數