Skip to content

Instantly share code, notes, and snippets.

@mattbennett
Created December 18, 2014 13:38
Show Gist options
  • Save mattbennett/f19a0ab74b7ce0726859 to your computer and use it in GitHub Desktop.
Save mattbennett/f19a0ab74b7ce0726859 to your computer and use it in GitHub Desktop.
Shared kombu connection
import eventlet
eventlet.monkey_patch()
from kombu import Exchange, Queue
from kombu.messaging import Consumer
exchange = Exchange('exchange', type='direct')
queue = Queue('queue', exchange, routing_key='queue')
if __name__ == '__main__':
from kombu import Connection
connection = Connection('amqp://guest:guest@localhost:5672//')
def handle_message(body, message):
print body
message.ack()
def run():
with connection.channel() as channel:
with Consumer(channel, queue,
accept=['json'],
callbacks=[handle_message]):
connection.drain_events(timeout=10)
w1 = eventlet.spawn(run)
w2 = eventlet.spawn(run)
w1.wait()
w2.wait()
@mattbennett
Copy link
Author

Raises:

RuntimeError: Second simultaneous read on fileno 4 detected.  Unless you really know what you're doing, make sure that only one greenthread can read any particular socket.  Consider using a pools.Pool. If you do know what you're doing and want to disable this error, call eventlet.debug.hub_prevent_multiple_readers(False) - MY THREAD=<built-in method switch of GreenThread object at 0x10542bd70>; THAT THREAD=FdListener('read', 4, <built-in method switch of GreenThread object at 0x10542bcd0>, <built-in method throw of GreenThread object at 0x10542bcd0>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment