ActiveMQ delete specific message


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.

When creating the consumer, create it by IMessageConsumer consumer = session.CreateConsumer(destination,"REFCODE > 200") or similar depending what you need to look for. Then just call consumer.receive(timeout_val); until you pulled all selected messages of the queue. <a href="http://activemq.apache.org/selectors.html" rel="nofollow">Info about AMQ selectors</a>


  • Can you publish a message while processing a queue in RabbitMQ .Net Client?
  • XMS.NET hanging indefinitely on factory.CreateConnection(“username”, null);
  • Send and Receive XML formatted text to IBM WebSphere MQ using XMS
  • How can I recognize ActiveMQ disconnect using NMS and C#
  • How to declare global NodeJS variables within my ambient declaration file?
  • Updating Dojo provide
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Declaring variable dynamically in VB.net
  • GridView breaks while scrolling
  • Limiting recursion to certain level - Duplicate rows
  • MongoDb aggregation
  • SplFileObject error failed to open stream: No such file or directory
  • one Local Olampyad Questions on Informatic in 2011
  • Replace value with Factor in r data.table
  • Could not find rake using whenever rails
  • Splitting given String into two variables - php
  • Align navbar back button on right side
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • How can I use Kendo UI with Razor?
  • php design question - will a Helper help here?
  • Comma separated Values
  • AngularJs get employee from factory
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Trying to get generic when generic is not available
  • How do I configure my settings file to work with unit tests?
  • embed rChart in Markdown
  • Turn off referential integrity in Derby? is it possible?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Add sale price programmatically to product variations
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How do I use LINQ to get all the Items that have a particular SubItem?