场景:我向名为 JUST.CN 的队列发送五万条消息。并且每 1000 条消息设置一个消息属性字符串“myfilter='abc'”。现在我创建具有相同选择器的消费者来消费消息。但是消费速度非常慢,尤其是在 30000 条消息之后。我无法更改 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 的选择器使用任何特殊设置吗?提前感谢您的任何意见。