1
有沒有辦法列出ActiveMQ中的所有活動隊列?我正在使用Apache.NMS與來自C#的ActiveMQ進行通信。在C#中使用ActiveMQ Apache.NMS列出可用隊列
我在庫中看不到任何直接的方法。
有沒有辦法列出ActiveMQ中的所有活動隊列?我正在使用Apache.NMS與來自C#的ActiveMQ進行通信。在C#中使用ActiveMQ Apache.NMS列出可用隊列
我在庫中看不到任何直接的方法。
請試試這個。
public void Test()
{
//Please create connection and session @ this point
String QUEUE_ADVISORY_DESTINATION = "ActiveMQ.Advisory.Queue";
IDestination dest = Session.GetTopic(QUEUE_ADVISORY_DESTINATION);
using (IMessageConsumer consumer = Session.CreateConsumer(dest))
{
IMessage advisory;
while ((advisory = consumer.Receive()) != null)
{
ActiveMQMessage amqMsg = advisory as ActiveMQMessage;
if (amqMsg.DataStructure != null)
{
DestinationInfo info = amqMsg.DataStructure as DestinationInfo;
if (info != null)
{
Console.WriteLine(" Queue: " + info.Destination.ToString());
}
}
}
}
Console.WriteLine("Listing Complete.");
}
這不是保證列出隊列的方式。請參閱this answer。
上述解決方案包含一個缺陷。如果你會嘗試得到的消息是這樣的:
consumer.Receive()
你會等待無限長的時間,而不會與隊列的信息到ActiveMQ的被髮生新的事件。
我建議設置超時:
consumer.Receive(TimeSpan.FromMilliseconds(2000))
並查看示例offitial site
嘗試這個..謝謝......至少有一個方向。 – Zach