Hi-

I am exploring the Browser feature of the Apache NMS AMQP API with the
latest ActiveMQ and also with the latest Artemis on Docker Desktop,
and have been unable to iterate over messages in a queue. With both
Message Brokers, the Browser will connect with no errors. It just
doesn’t get or go through the messages. I’m wondering if I need to
enable some feature on the Message Brokers.  Or maybe there is
something else I’m missing?

Here is some similar example code:

IConnectionFactory factory = new NmsConnectionFactory("amqp://localhost:5672");
using IConnection connection = factory.CreateConnection();
connection.Start();
using ISession session =
connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
IQueue queue = session.GetQueue("FOO.BAR");

using IMessageProducer producer = session.CreateProducer(queue);

for (int i = 0; i < 10; i++)
    producer.Send(producer.CreateTextMessage(i.ToString()));

Console.WriteLine("Browsing messages in queue: " + queue.QueueName);
IMessage? message;
using IQueueBrowser browser = session.CreateBrowser(queue);
var enumerator = browser.GetEnumerator();
while (enumerator.MoveNext())
{
    System.Collections.IEnumerator enumerator1 = enumerator;
    message = enumerator1.Current as IMessage;
    if (message is ITextMessage textMessage)
        Console.WriteLine($"Found message: {textMessage.Text}");
}

Console.WriteLine("Consuming messages in queue: " + queue.QueueName);
using IMessageConsumer consumer = session.CreateConsumer(queue);
do
{
    message = consumer.Receive(TimeSpan.FromSeconds(1));
    Console.WriteLine($"Found message: {(message as ITextMessage)?.Text}");
}
while (message is not null);


Thanks for the help.

John

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to