Setting custom connection name via client_properties doesn't work when connecting using an amqp:// URL

See original GitHub issue

Repro:

import asyncio
import aio_pika


async def main():
    # named connection using URL (works)
    abc_conn = await aio_pika.connect("amqp://localhost?name=ABC")

    # named connection using client properties (doesn't work)
    def_conn = await aio_pika.connect("amqp://localhost",
                                      client_properties={'connection_name': 'DEF'})

    # named connection using kwargs only (works)
    xyz_conn = await aio_pika.connect(host="localhost", name='XYZ')

    input('hit enter to close connections...')

    for conn in [abc_conn, def_conn, xyz_conn]:
        await conn.close()


if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())

Expected:

https://aio-pika.readthedocs.io/en/latest/apidoc.html#aio_pika.connect only gives the client_properties example of setting the connection name, so it’s not obvious that it won’t work when using a URL to connect, and the trick of using a name query parameter doesn’t seem to be documented anywhere (only figured it out by reading through aiormq code).

Actual:

The snippet above will set the connection name in the RabbitMQ management UI as expected for ABC and XYZ, but not DEF.

Environment:

$ pip freeze
aio-pika==6.5.2
aiormq==3.2.1
idna==2.9
multidict==4.7.5
pamqp==2.3.0
yarl==1.4.2

Plus RabbitMQ 3.8.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

3reactions
LECbgcommented, Oct 4, 2022

I’m using aio-pika 8.2.3 and I don’t think it’s fixed, aio_pika.connect(...) and aio_pika.connect_robust(...) pass client_properties only to make_url(...) and that function just returns the URL when given. Probably, when manually instantiating Connection and RobustConnection, passing connection_name works, but not for this methods.


EDIT: After trying over and over again and debugging all over the 3 libraries, I’ve managed to set a custom name only without specifying the URL and by setting the property name, NOT connection_name.

i.e.:

import aio_pika

await aio_pika.connect_robust(
    host='localhost',
    port=5672,
    login='guest',
    password='guest',
    virtualhost='/',
    ssl=False,
    client_properties={
        'name': 'Write connection'
    }
)
1reaction
JustinTArthurcommented, Feb 23, 2022

For anyone waiting on this, it is fixed in the newly released aio-pika 7.x

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set connection name with amqplib - node.js - Stack Overflow
Yes you can set the connection name by passing it in the client properties: amqp.connect('amqp://localhost', {clientProperties: ...
Read more >
Connections - RabbitMQ
This guide covers various topics related to connections except for network tuning or most networking-related topics. Those are covered by the Networking and ......
Read more >
Connection Parameters — pika 1.2.1 documentation
Set the tcp options for the underlying socket. Parameters: url (str) – The AMQP URL to connect to. ssl_options ...
Read more >
ConnectionFactory (RabbitMQ Java Client 5.15.0 API)
Most connection and socket settings are configured using this factory. ... be configured here and will apply to all connections produced by this...
Read more >
Spring AMQP
As a result, you need not use that bean explicitly in the simple Java ... When using a large number of connections, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found