Azure / amqpnetlite

AMQP 1.0 .NET Library
Apache License 2.0
401 stars 143 forks source link

How do I set the connection ID with Amqpnetlite #450

Closed eagle275 closed 3 years ago

eagle275 commented 3 years ago

As headline says - how do I set programmatically the connection ID for the created connection going from a factory

We send messages to a broker system and have confirmation that packets arrive and pass through a firewall .. so they should arrive at the broker - alas "they" cant find them - most likely because this broker receives all kinds of messages for one of Germany's biggest corporations. The broker runs on ActiveMQ - and when I test, it doesnt offer any option to search - so if one queue receives many messages it gets tiresome to find the specific message. We typically send less than 20 over a full day...

So the connection ID would really help ... how do I set it - or at least find out, what connection ID is used while sending an AMQP message?

Thanks in advance

Havret commented 3 years ago

Hi @eagle275

You can set ConnectionId on Open frame. The parameter you need to set is called ContainerId. Just use this overload of CreateAsync method on ConnectionFactory object:

public Task<Connection> CreateAsync(Address address, Open open = null, OnOpened onOpened = null);

By default ContainerId is resolved as follows:

"AMQPNetLite-" + Guid.NewGuid().ToString("N").Substring(0, 8)

xinchen10 commented 3 years ago

Alternatively you can use the connection factory to create a connection. The factory settings support many protocol level configurations.

    ConnectionFactory factory = new ConnectionFactory();
    factory.AMQP.ContainerId = "my-amqp-container";
    Connection connection = await factory.CreateAsync(address);
eagle275 commented 3 years ago

Thank you for your answers .. infact I already set the ContainerId over the factory much like xinchen10 shows. I only didnt know that "again" somebody decided to use a different name ^^ Issue can be closed !