apprise icon indicating copy to clipboard operation
apprise copied to clipboard

Support for AMQ Protocol

Open gaby opened this issue 3 years ago • 7 comments

:bulb: The Idea Add support for AMQ protocol, more information about the protocol available here.

AMQ is heavily used by systems integrated via ActiveMQ, RabbitMQ

The most recommended library is Pika, there's also aio-pika with Async Support.

Example publisher using aio-pika:

import asyncio
import aio_pika


async def main(loop):
    connection = await aio_pika.connect_robust(
        "amqp://guest:[email protected]/", loop=loop
    )

    routing_key = "test_queue"

    channel = await connection.channel()    # type: aio_pika.Channel

    await channel.default_exchange.publish(
        aio_pika.Message(
            body='Hello {}'.format(routing_key).encode()
        ),
        routing_key=routing_key
    )

    await connection.close()


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(loop))
    loop.close()

gaby avatar Sep 25 '21 01:09 gaby

We'll keep this in the queue :slightly_smiling_face: . For this request, i presume it would be similar to MQTT where a 3rd party library becomes a dependant?

Currently all of the Apprise plugins work with all versions of Python (back to v2.7). This implementation would be restricted to v3.4+ (as per limitations of dependant third party). IT would also limit the AMQP protocol to only version 0.9 (which i believe is still widely used, but v1.0+ has been out for some time now as well).

Thoughts?

caronc avatar Sep 29 '21 14:09 caronc

According to RabbitMQ specification they plan to support AMQP 0.9 indefinitely because 1.0 is completely different protocol. More info here.

The most know library Pika does have support for Python 2.7, unlike aio-pika which is 3.4+. Pika should work fine for Apprise.

gaby avatar Oct 01 '21 02:10 gaby

@caronc Any updates on this?

gaby avatar Sep 05 '22 15:09 gaby

@gaby I have not forgotten this request, but i just have not gotten the time to tackle it. If you feel brave, you could try it yourself :slightly_smiling_face:

Even just a basic implementation of it by leveraging the new custom plugins you can write (see here). If you helped me with just the basics that you were expecting, it would save me some research with the library by using your code examples for a full implementation.

caronc avatar Sep 05 '22 18:09 caronc

No worries, I will try to take a look :-)

gaby avatar Sep 06 '22 13:09 gaby

One thing to consider is that there are 2 versions of AMQP that are both very active; v1.0 and v0.9.x

I presume we ant to try to support both?

  • Apache Qpid seems to be a good route to go for v1.0 support
  • And Pika i believe is the library of choice for v0.9.x versions

Hence the syntax i guess would be something like:

  • amqp://user:pass@host/topic?ver=1.0
  • amqps://user:pass@host/topic?ver=0.9

If no ver is specified, then it would default to v1.0. It might be overkill to support both... or maybe not?

In the linked ticket (#656) there was reference to these platforms:

  • https://cloud.google.com/pubsub
  • https://aws.amazon.com/pub-sub-messaging/

Edit: I can't find on either cloud link above what version of AMQP they use.

caronc avatar Feb 19 '23 02:02 caronc

@caronc Almost everything uses amqp 0.9.1, the v1.0 is a completely different protocol. More info [here] (https://stackoverflow.com/questions/28402374/amqp-0-9-1-vs-1-0).

I was recently doing an amqp implementation and it should be very straight forward to do using aio-pika and the worker helper

gaby avatar Feb 19 '23 11:02 gaby