ActiveMQ删除特定消息 [英] ActiveMQ delete specific message
本文介绍了ActiveMQ删除特定消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码接收未删除的邮件。现在,我需要添加一些过滤条件并删除一些消息。我的问题是当其他邮件应留在队列中时如何删除特定邮件?
I use the following code to recieve messages without deletion. Now I need to add some filtering and delete some of the messages. My question is how to delete a specific message while other messages should stay in the queue?
Uri connecturi = new Uri("activemq:tcp://model.net:61616");
IConnectionFactory factory = new NMSConnectionFactory(connecturi);
List<ModelBuilderBase> result = new List<ModelBuilderBase>();
using (IConnection connection = factory.CreateConnection())
using (ISession session = connection.CreateSession())
{
IDestination destination = SessionUtil.GetDestination(session, "queue://cidModelbuilderQ");
using (IMessageConsumer consumer = session.CreateConsumer(destination))
{
connection.Start();
var q = session.GetQueue("cidModelbuilderQ");
var b = session.CreateBrowser(q);
var msgs = b.GetEnumerator();
while (msgs.MoveNext())
{
ITextMessage message = msgs.Current as ITextMessage;
if (message.Properties[MANDATOR] == null || message.Properties[REFCODE] == null)
continue;
var mandator = message.Properties[MANDATOR].ToString();
var refCode = message.Properties[REFCODE].ToString();
result.Add(ModelBuilderFactory.Instance.GetInstance(refCode, mandator));
}
}
}
推荐答案
使用选择器并获取这些消息。
Use selectors and get these messages.
创建使用者时,由
创建。IMessageConsumer Consumer = session.CreateConsumer(destination, REFCODE> 200)
或类似内容,取决于您要查找的内容。
然后只需调用Consumer.receive(timeout_val);直到拉出队列中所有选定的消息。
有关AMQ选择器的信息
这篇关于ActiveMQ删除特定消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文