Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

Does aioamqp work? #52

Closed zloidemon closed 8 years ago

zloidemon commented 8 years ago

Hello,

Does driver work?

I only see this:

(.venv)vg %> python test_receive.py
b'py2.queue'
b'py2.queue'
b'py2.queue'
b'py2.queue'
b'py2.queue'
# rabbitmqctl list_channels
Listing channels ...
<rabbit@tt01.1.11368.0> python_test 1   5

I sent 3 messages to:

(.venv)vg %> python send.py 
Hello World!
(.venv)vg %> python send.py
Hello World!
(.venv)vg %> python send.py
Hello World!

But I still see and expecting messages:

(.venv)vg %> python test_receive.py
b'py2.queue'
b'py2.queue'
b'py2.queue'
b'py2.queue'
b'py2.queue'

Okey, time to run receiver based on pika:

(.venv)vg %> python recive.py 
Received b'Hello backend2'
Received b'Hello backend2'
Received b'Hello backend2'
# rabbitmqctl list_channels
Listing channels ...
<rabbit@tt01.1.11368.0> python_test 1   5
<rabbit@tt01.1.11424.0> python_test 1   0

test_receive.py:

#!/usr/bin/env python

import asyncio
import aioamqp

@asyncio.coroutine
def callback(body, envelope, properties):
    print(body)

@asyncio.coroutine
def receive():
    try:
        transport, protocol = yield from aioamqp.connect(host='10.10.80.23', port=5672,
            login='python_test', password='python_test', virtualhost='hello')
    except aioamqp.AmqpClosedConnection:
        print("closed connections")
        return

    channel = yield from protocol.channel()
    queue_name = 'py2.queue'

    yield from asyncio.wait_for(channel.queue(queue_name, durable=False, auto_delete=False), timeout=10)

    yield from asyncio.wait_for(channel.basic_consume(queue_name, callback=callback), timeout=10)

asyncio.get_event_loop().run_until_complete(receive())
asyncio.get_event_loop().run_forever()

send.py:

#!/usr/bin/env python
import pika

credentials = pika.PlainCredentials('python_test', 'python_test')

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='10.10.80.25',credentials=credentials, virtual_host='hello'))
channel = connection.channel()

channel.queue_declare(queue='py2.queue')

channel.basic_publish(exchange='',
                      routing_key='hello',
                      body='Hello backend2')
print("Hello World!")
connection.close()

recive.py:

#!/usr/bin/env python
import pika

credentials = pika.PlainCredentials('python_test', 'python_test')

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='10.10.80.23',credentials=credentials, virtual_host='hello'))
channel = connection.channel()

channel.queue_declare(queue='py2.queue')

def callback(ch, method, properties, body):
    print("Received {}".format(body))

channel.basic_consume(callback,
                      queue='hello',
                      no_ack=True)

channel.start_consuming()
dzen commented 8 years ago

Hello zloidemon,

I didn't have the material to test it right now, but:

I will write a little test tomorow if you want.

zloidemon commented 8 years ago

Hi,

dzen commented 8 years ago

Hello @zloidemon,

I started your send.py script, and modified the connexions settings to connect to my own rabbitmq instance.

I have to sum up what you're currently doing with your 3 scripts:

send.py

This script creates a queue py2.queue and sends Hello backend2 to the default exchange (empty string) and routing messages to hello queue

tests_recive.py

Waits on py2.queue to get some messages and print them in the console

recive.py

Declare py2.queue queue and consume message from queue hello.

I'm aware of not having enought documentation on the current library version, I'm focusing first on bugs. But please, don't be rude. This is not a real bug issue, and you didn't correctly described the issue you're having. May I suggest you to install the shiny web management pluggin https://www.rabbitmq.com/management.html to effectively know what's going on your rabbitmq cluster ?

Thank you for your issue.

zloidemon commented 8 years ago

Thank you! It works for me. I missed with channel.