方案:我發送五萬消息到名爲JUST.CN的隊列。然後每消息1000個消息,我會創建一個消息propertyString「myfilter ='abc'」。現在,我使用相同的選擇器創建消費者以使用消息。但是,在30000消息之後,特別是消費速率非常慢。我無法更改activeMQ中的默認配置。 核心代碼如下:activeMQ上消費者的選擇問題
IDestination destination = SessionUtil.GetDestination(session, "JUST.CN");
IMessageProducer producer = session.CreateProducer(destination);
string msg = "Hello hello hello world!~~testing~Hello hello hello world!~~testing~";
for (int i = 0; i < 50000; i++)
{
ITextMessage message;
if (i % 1000 == 0)
{
message = session.CreateTextMessage(msg);
message.Properties.SetString("myfilter", "abc");
}
else
{
message = session.CreateTextMessage(msg);
}
producer.Send(message, MsgDeliveryMode.Persistent, MsgPriority.Normal, TimeSpan.MinValue);
}
消費者的代碼:
IDestination destination = SessionUtil.GetDestination(session, "JUST.CN");
IMessageConsumer consumer = session.CreateConsumer(destination, "myfilter='abc'", false);
int count = 0;
DateTime dtstart = DateTime.Now;
for (int i = 0; i < 50; i++)
{
IMessage iMsg = consumer.Receive();
ITextMessage msg = (ITextMessage)iMsg;
Console.WriteLine(msg.Text);
count++;
}
DateTime dtend = DateTime.Now;
TimeSpan time = dtend - dtstart;
Console.WriteLine(time);
Console.WriteLine(count);
是否有我需要使用的選擇到ActiveMQ的任何特殊的設置? 預先感謝您的任何意見。
謝謝Jake.Your答案幫助我lot.Creating虛擬目的地和發送消息there.This會導致大量queue.Is有任何其他方式做到這一點有一個隊列?也許這是爲每個消費者創建一個隊列的唯一方法,如果發送消息給特定的消費者。該系統將有1000個消費者到PTP通信。我無法想象在ActiveMQ服務器上會發生什麼。 – Yolanda
一般而言,經紀人擁有大量目的地即可。聽起來你可能會使用一組錯誤的功能(隊列可能不是解決特定問題的最佳方法)。如果你能說出你想要達到的目標,我可能會指出你正確的方向。 –
我們的系統中將有大約1000個用戶。我想實現彼此之間的點對點通信(也許可能有300個用戶同時在線),並且消息將被持久存儲在activemq中代理用戶A發送一條消息給用戶B. userB會在線接收消息,一個用戶可能有三種類型的端點,比如WebPage,Instant Communication Tool和Mobile等。這意味着一條消息會被髮送到所有使用的客戶端。有沒有什麼好的方法來實現這一點?謝謝傑克。 – Yolanda