Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

Connection and channel names #89

Closed jared-mackey closed 8 years ago

jared-mackey commented 8 years ago

Is there a way to get the connection and channel names from the driver?

I want to be able to hit the API from rabbitmq and query for just the one connection/channel.

dzen commented 8 years ago

Hello @mackeyja92,

I don't get it. What do you want to do ? There is no channel names in AMQP, but there are id. Note that a Channel is created and managed during one connection. There is no way to share them between multiple connections

jared-mackey commented 8 years ago

When querying the rabbitmq API it gives us a name, for example when I hit rabbit.example.com/api/connections the return data is below. How can I get the name property directly off a AmqpProtocol? I need this to be able to hit the API and directly query for just one connection. In my data below I only have one, but this won't always be the case. Also, channels have a similar naming scheme.

/api/connections

[
   {
      "recv_oct":442,
      "recv_oct_details":{
         "rate":0.0
      },
      "send_oct":646,
      "send_oct_details":{
         "rate":0.0
      },
      "recv_cnt":9,
      "send_cnt":9,
      "send_pend":0,
      "state":"running",
      "channels":1,
      "type":"network",
      "node":"rabbit@rmq",
      "name":"10.0.2.2:50161 -> 172.19.0.2:5672",
      "port":5672,
      "peer_port":50161,
      "host":"172.19.0.2",
      "peer_host":"10.0.2.2",
      "ssl":false,
      "peer_cert_subject":null,
      "peer_cert_issuer":null,
      "peer_cert_validity":null,
      "auth_mechanism":"AMQPLAIN",
      "ssl_protocol":null,
      "ssl_key_exchange":null,
      "ssl_cipher":null,
      "ssl_hash":null,
      "protocol":"AMQP 0-9-1",
      "user":"guest",
      "vhost":"/",
      "timeout":60,
      "frame_max":131072,
      "channel_max":0,
      "client_properties":{
         "copyright":"BSD",
         "product_version":"0.7.0",
         "product":"aioamqp",
         "capabilities":{
            "connection.blocked":false,
            "consumer_cancel_notify":true
         }
      },
      "connected_at":1459782362196
   },
]

Essentially, I just need some way to identify a connection from the AmqpProtocol and a channel from a Channel.

I think I might be able to implement this myself by adding something in the client properties, but I wanted to see if there was a standard way of doing this before doing so.

dzen commented 8 years ago

As same as for node which is your node name, this is juste a reprensentation of the connection, not a RabbitMQ or AMQP thing

jared-mackey commented 8 years ago

I see what you are saying. I wasn't sure if there was already a way implemented to that representation from the AmqpProtocol or not. I really wanted to figure out a way to find one specific connection in the list of connections. So I was able to solve it with this below.

    async def connect(self, **kwargs):  
        if not self.uuid:
            self.uuid = uuid.uuid4()
        client_properties = kwargs.pop('client_properties', {})
        client_properties['uuid'] = str(self.uuid)
        kwargs['client_properties'] = client_properties
        self.transport, self.protocol = await connect(
            host=self.host,
            port=self.port,
            login=self.login,
            password=self.password,
            virtualhost=self.vhost,
            ssl=self.ssl,
            verify_ssl=self.verify_ssl,
            **kwargs
        )

Then later when you have the list of connections you can just look in the client properties and find the uuid representing your connection.

dzen commented 8 years ago

I'm not sure of what you want to do here

jared-mackey commented 8 years ago

The above code is a valid work around. Thanks