summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--oslo_messaging/_drivers/common.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/oslo_messaging/_drivers/common.py b/oslo_messaging/_drivers/common.py
index 44cfe55..54ba98b 100644
--- a/oslo_messaging/_drivers/common.py
+++ b/oslo_messaging/_drivers/common.py
@@ -399,11 +399,32 @@ class ConnectionContext(Connection):
399 """Create a new connection, or get one from the pool.""" 399 """Create a new connection, or get one from the pool."""
400 self.connection = None 400 self.connection = None
401 self.connection_pool = connection_pool 401 self.connection_pool = connection_pool
402
403 # NOTE(sileht): Even if rabbit only has one Connection class this
404 # connection can be used for only one of two purposes:
405 #
406 # * receiving messages from the broker (read actions on the socket)
407 # * sending messages to the broker (write actions on the socket)
408 #
409 # Using one Connection class instance for both purposes will result in
410 # eventlet complaining about multiple greenthreads that read/write the
411 # same fd concurrently. This is because 'send' and 'listen' run in
412 # different greenthreads and the code inside a connection class is not
413 # concurrency safe. The 'purpose' parameter ensures that no connection
414 # is used for both sending and receiving messages.
415 #
416 # The rabbitmq driver allocates connections in the following manner:
417 # * driver.listen*(): each call creates a new dedicated
418 # 'PURPOSE_LISTEN' connection for the listener
419 # * driver.send*(): senders are assigned a connection from a pool of
420 # 'PURPOSE_SEND' connections maintained by the driver.
421 # * One 'PURPOSE_LISTEN' connection is dedicated to waiting for replies
422 # to rpc calls.
423
402 pooled = purpose == PURPOSE_SEND 424 pooled = purpose == PURPOSE_SEND
403 if pooled: 425 if pooled:
404 self.connection = connection_pool.get() 426 self.connection = connection_pool.get()
405 else: 427 else:
406 # a non-pooled connection is requested, so create a new connection
407 self.connection = connection_pool.create(purpose) 428 self.connection = connection_pool.create(purpose)
408 self.pooled = pooled 429 self.pooled = pooled
409 self.connection.pooled = pooled 430 self.connection.pooled = pooled