1

I cannot seem to get the code running - I've been using Pika and keen to try out this thread safe and possibly neater version.

import rabbitpy

with rabbitpy.Connection('amqp://guest:guest@localhost:5672/%2f') as conn:
    with conn.channel() as channel:
        queue = rabbitpy.Queue(channel, 'example')

        # Exit on CTRL-C
        try:
            # Consume the message
            for message in queue:
                message.pprint(True)
                message.ack()

        except KeyboardInterrupt:
            print 'Exited consumer' 

The error I get:

Traceback (most recent call last):
  File "newshift.py", line 3, in <module>
    with rabbitpy.Connection('amqp://guest:guest@localhost:5672/%2f') as conn:
AttributeError: 'module' object has no attribute 'Connection'

My systems settings are:

numpy==1.11.2
pamqp==1.6.1
pandas==0.19.0
pika==0.10.0
pkg-resources==0.0.0
python-dateutil==2.5.3
pytz==2016.7
rabbitpy==1.0.0
six==1.10.0
SQLAlchemy==1.1.3

dir(rabbitpy)
['__builtins__', '__doc__', '__file__', '__name__', '__package__']

Somehow the classes are not seen when loading in the module

Original issue was caused by .pyc files hanging around, but new error message is:

Traceback (most recent call last):
  File "newshift.py", line 15, in <module>
    print 'Exited consumer' 
  File "/home/brett/code/SimpleConsumers/local/lib/python2.7/site-packages/rabbitpy/connection.py", line 149, in __exit__
    raise exc_val
rabbitpy.exceptions.AMQPNotFound: <pamqp.specification.Channel.Close object at 0x7f39a91da7d0>
disruptive
  • 5,687
  • 15
  • 71
  • 135
  • Do you wrap it in the class? If you have a class called `class RabbitPy(object)`, you need to call it like `from rabbitpy import RabbitPy as rp`, and then try to use connection like so: `rp.Connection('amqp://guest:guest@localhost:5672/%2f')`. I've had the similar issue when I was testing my setup. – mutantkeyboard Nov 02 '16 at 17:13
  • 2
    did you use name `rabbitpy` for you file (`rabbitpy.py`) or folder ? Then now you import this file instead original module. Check `print( rabbitpy.__file__ )` – furas Nov 02 '16 at 17:43
  • @furas I updated my question now. I did indeed have this naming issue - doh, but not cannot seem to get the other libraries working. – disruptive Nov 04 '16 at 20:05
  • I tried this code but it doesn't work for me - I got the same error. But I have no problem with examples on https://www.rabbitmq.com/tutorials/tutorial-one-python.html – furas Nov 04 '16 at 23:00
  • I tried sending with `pika` and receive with `rabbitpy` and it (almost) works if `rabbitpy` uses queue with name `hello` instead of `example` (because `pika` use name `hello`). I think `rabbitpy` doesn't work because it tries to use non-existing queue with name `example` but it doesn't create it first. Pika always create queue `hello` (in both examples - for sending and for receiving - read tutorial) so it always works. – furas Nov 04 '16 at 23:08

1 Answers1

1

rabbitpy.exceptions.AMQPNotFound: <pamqp.specification.Channel.Close

I think rabbitpy gives this error because it tries to connect to non-existing queue with name example

queue = rabbitpy.Queue(channel, 'example')

but rabbitpy doesn't create this queue if it doesn't exist yet.

I checked examples with pika and they work because pika creates queue (with name hello) when it doesn't exists so it can send and receive from this queue safely.

pika automatically create queue in both situations - when you send or receive message.


You can check existing queues in rabbitmq with command (on Linux)

sudo rabbitmqctl list_queues

ie. result

Listing queues ...
celery  3
hello   0
...done.

If I send message with pika then I can receive it with rabbitpy because pika creates queue if it doesn't exist and then rabbitpy can safely use this queue.


It seams you have to use queue.declare() to create queue if it doesn't exist.

import rabbitpy

with rabbitpy.Connection('amqp://guest:guest@localhost:5672/%2f') as conn:
    with conn.channel() as channel:
        queue = rabbitpy.Queue(channel, 'example')
        queue.declare() # <---
furas
  • 134,197
  • 12
  • 106
  • 148