I am trying to read through ActiveMQ messages and according some filters to process some of them or leave the other messages in the queue. I use NMS API with the following code:
        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();
                ITextMessage message;
                while ((message = consumer.ReceiveNoWait() as ITextMessage) != null)
                {
                    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));
                }
            }
Problem is that after a message is received the message is deleted. Can I somehow change this behavior and delete the messages only manually after a successful processing? }