Azure / amqpnetlite

AMQP 1.0 .NET Library
Apache License 2.0
396 stars 141 forks source link

Can't create a pair link due of Attach.LinkName override #582

Closed Gsantomaggio closed 1 month ago

Gsantomaggio commented 1 month ago

The issue was already raised here https://github.com/Azure/amqpnetlite/issues/360

Description

I will try to propose an easy solution ( let's hope). Btw, given this code:

        var receiveAttach = new Attach()
        {

            SndSettleMode = SenderSettleMode.Settled,
            RcvSettleMode = ReceiverSettleMode.First,
            Properties = new Fields
            {
                {new Symbol("paired"), true}
            },
            LinkName = "management-link-pair",
            Source = new Source()
            {
                Address = "/management",
                ExpiryPolicy = new Symbol("LINK_DETACH"),
                Timeout = 0,
                Dynamic = false,
                Durable = 0,
            },
            Handle = 1,
            Target = new Target()
            {
                Address = "/management",
                ExpiryPolicy = new Symbol("SESSION_END"),
                Timeout = 0,
                Dynamic = false,

            },
        };

        var sender = new SenderLink(
            managementSession, "sender", senderAttach, (link, attach1) =>
            {
                testOutputHelper.WriteLine("Attached");
            });

        var receiver = new ReceiverLink(
            managementSession, "receive", receiveAttach, (link, attach1) =>
            {
                testOutputHelper.WriteLine("Attached");
            });

The library will replace the LinkName with the name

In this case, each value you set to the Attach.LinkName will be replaced. The library does not allow the use of the same name:

var sender = new SenderLink(
            managementSession, "mylink", senderAttach, (link, attach1) =>
            {
                testOutputHelper.WriteLine("Attached");
            });

        var receiver = new ReceiverLink(
            managementSession, "mylink", receiveAttach, (link, attach1) =>
            {
                testOutputHelper.WriteLine("Attached");
            });

raises: mylink has been attached

To create the pair the linkname must be unique ref: https://docs.oasis-open.org/amqp/linkpair/v1.0/cs01/linkpair-v1.0-cs01.html#_Toc51331304

Possible solution(?)

I am not sure it can work but the easy solution would be like this:

if (attach.LinkName == String.Empty){
   attach.LinkName = this.name;
}

Thank you

xinchen10 commented 1 month ago

I am fixing the bug by including link role in link name comparison.

Gsantomaggio commented 1 month ago

Thank you

michaelklishin commented 1 month ago

@xinchen10 thank you. Much appreciated by the entire RabbitMQ team!

xinchen10 commented 1 month ago

I made the changes. Now it should allow the same name for two links with different roles.

Gsantomaggio commented 1 month ago

It works. Thank you

Gsantomaggio commented 1 month ago

@xinchen10 may I ask when the new version will be released? thank you

xinchen10 commented 1 month ago

Version 2.4.10 is released.