Hi,

I have stumbled across an issue that I believe is with Apache.NMS.AMQP
library. I'm using the latest stable version, 2.4.0, for my .NET C# service
for message handling, with the latest Apache Artemis and Apache ActiveMQ
message brokers.
Both the web page on Uri Configuration (
https://activemq.apache.org/components/nms/providers/amqp/uri-configuration)
and the GitHub project (
https://github.com/apache/activemq-nms-amqp/blob/main/docs/configuration.md)
state that "nms.clientId" should be used in the Connection Uri to configure
the Client ID.
However, I have found that using "nms.clientId" breaks consumer
functionality for Shared Consumers, who will then receive every message in
the topic. And that, excluding the query parameter, allows Shared Consumers
to function correctly, with each consumer receiving only their share of the
messages.
Please also note that if one does not include the parameter in the Uri but
instead sets the ClientId on the connection object itself, the Shared
Customer will still not function correctly, having the same issue as using
the parameter in the Uri.
However, by not including the nms.clientId parameter, a Client ID is
automatically generated, which I guess is why it works correctly.
Nevertheless, it is less than ideal not being able to use my own Client ID.
But maybe I'm doing something wrong. Here is some simple example code using
the nms.clientId parameter that has the issue:

static async Task SharedAsync(string clientId, CancellationToken
stoppingToken)
{
    string uri =
$"amqp://localhost:61616?nms.username=artemis&nms.password=artemis&nms.clientId={clientId}";
    var connecturi = new Uri(uri);
    var factory = new NMSConnectionFactory(connecturi);
    using IConnection connection = await factory.CreateConnectionAsync();
    connection.Start();
    using ISession session = await connection.CreateSessionAsync();
    ITopic destination = await session.GetTopicAsync("topic-name");
    using var consumer = await
session.CreateSharedConsumerAsync(destination, "sub-name");
    while (!stoppingToken.IsCancellationRequested)
    {
        var msg = await
consumer.ReceiveAsync(TimeSpan.FromMicroseconds(250)) as ITextMessage;
        if (msg is not null)
        {
            // process message
        }
    }
}


Thanks,
John

Reply via email to