desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Publish to the channel with the given exchange, routing key and body. Returns a boolean value indicating the success of the operation. This is the legacy BlockingChannel method for publishing. See also `BlockingChannel.publish` that provides more information about failures. For more information on basic_publish and wh...
def basic_publish(self, exchange, routing_key, body, properties=None, mandatory=False, immediate=False):
try: self.publish(exchange, routing_key, body, properties, mandatory, immediate) except (exceptions.NackError, exceptions.UnroutableError): return False else: return True
'Publish to the channel with the given exchange, routing key, and body. Unlike the legacy `BlockingChannel.basic_publish`, this method provides more information about failures via exceptions. For more information on basic_publish and what the parameters do, see: http://www.rabbitmq.com/amqp-0-9-1-reference.html#basic.p...
def publish(self, exchange, routing_key, body, properties=None, mandatory=False, immediate=False):
if self._delivery_confirmation: with self._message_confirmation_result: self._impl.basic_publish(exchange=exchange, routing_key=routing_key, body=body, properties=properties, mandatory=mandatory, immediate=immediate) self._flush_output(self._message_confirmation_result.is_ready) ...
'Specify quality of service. This method requests a specific quality of service. The QoS can be specified for the current channel or for all channels on the connection. The client can request that messages be sent in advance so that when the client finishes processing a message, the following message is already held lo...
def basic_qos(self, prefetch_size=0, prefetch_count=0, all_channels=False):
with _CallbackResult() as qos_ok_result: self._impl.basic_qos(callback=qos_ok_result.signal_once, prefetch_size=prefetch_size, prefetch_count=prefetch_count, all_channels=all_channels) self._flush_output(qos_ok_result.is_ready)
'This method asks the server to redeliver all unacknowledged messages on a specified channel. Zero or more messages may be redelivered. This method replaces the asynchronous Recover. :param bool requeue: If False, the message will be redelivered to the original recipient. If True, the server will attempt to requeue the...
def basic_recover(self, requeue=False):
with _CallbackResult() as recover_ok_result: self._impl.basic_recover(callback=recover_ok_result.signal_once, requeue=requeue) self._flush_output(recover_ok_result.is_ready)
'Reject an incoming message. This method allows a client to reject a message. It can be used to interrupt and cancel large incoming messages, or return untreatable messages to their original queue. :param int delivery-tag: The server-assigned delivery tag :param bool requeue: If requeue is true, the server will attempt...
def basic_reject(self, delivery_tag=None, requeue=True):
self._impl.basic_reject(delivery_tag=delivery_tag, requeue=requeue) self._flush_output()
'Turn on RabbitMQ-proprietary Confirm mode in the channel. For more information see: http://www.rabbitmq.com/extensions.html#confirms'
def confirm_delivery(self):
if self._delivery_confirmation: LOGGER.error('confirm_delivery: confirmation was already enabled on channel=%s', self.channel_number) return with _CallbackResult() as select_ok_result: self._impl.add_callback(callback=select_ok_result.signal_once, replies=[pika.spec.Con...
'This method creates an exchange if it does not already exist, and if the exchange exists, verifies that it is of the correct and expected class. If passive set, the server will reply with Declare-Ok if the exchange already exists with the same name, and raise an error if not and if the exchange does not already exist,...
def exchange_declare(self, exchange=None, exchange_type='direct', passive=False, durable=False, auto_delete=False, internal=False, arguments=None):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as declare_ok_result: self._impl.exchange_declare(callback=declare_ok_result.set_value_once, exchange=exchange, exchange_type=exchange_type, passive=passive, durable=durable, auto_delete=auto_delete, internal=internal, nowait=False, arguments=argumen...
'Delete the exchange. :param exchange: The exchange name :type exchange: str or unicode :param bool if_unused: only delete if the exchange is unused :returns: Method frame from the Exchange.Delete-ok response :rtype: `pika.frame.Method` having `method` attribute of type `spec.Exchange.DeleteOk`'
def exchange_delete(self, exchange=None, if_unused=False):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as delete_ok_result: self._impl.exchange_delete(callback=delete_ok_result.set_value_once, exchange=exchange, if_unused=if_unused, nowait=False) self._flush_output(delete_ok_result.is_ready) return delete_ok_result.value.method_frame
'Bind an exchange to another exchange. :param destination: The destination exchange to bind :type destination: str or unicode :param source: The source exchange to bind to :type source: str or unicode :param routing_key: The routing key to bind on :type routing_key: str or unicode :param dict arguments: Custom key/valu...
def exchange_bind(self, destination=None, source=None, routing_key='', arguments=None):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as bind_ok_result: self._impl.exchange_bind(callback=bind_ok_result.set_value_once, destination=destination, source=source, routing_key=routing_key, nowait=False, arguments=arguments) self._flush_output(bind_ok_result.is_ready) return...
'Unbind an exchange from another exchange. :param destination: The destination exchange to unbind :type destination: str or unicode :param source: The source exchange to unbind from :type source: str or unicode :param routing_key: The routing key to unbind :type routing_key: str or unicode :param dict arguments: Custom...
def exchange_unbind(self, destination=None, source=None, routing_key='', arguments=None):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as unbind_ok_result: self._impl.exchange_unbind(callback=unbind_ok_result.set_value_once, destination=destination, source=source, routing_key=routing_key, nowait=False, arguments=arguments) self._flush_output(unbind_ok_result.is_ready) ...
'Declare queue, create if needed. This method creates or checks a queue. When creating a new queue the client can specify various properties that control the durability of the queue and its contents, and the level of sharing for the queue. Leave the queue name empty for a auto-named queue in RabbitMQ :param queue: The ...
def queue_declare(self, queue='', passive=False, durable=False, exclusive=False, auto_delete=False, arguments=None):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as declare_ok_result: self._impl.queue_declare(callback=declare_ok_result.set_value_once, queue=queue, passive=passive, durable=durable, exclusive=exclusive, auto_delete=auto_delete, nowait=False, arguments=arguments) self._flush_output(decla...
'Delete a queue from the broker. :param queue: The queue to delete :type queue: str or unicode :param bool if_unused: only delete if it\'s unused :param bool if_empty: only delete if the queue is empty :returns: Method frame from the Queue.Delete-ok response :rtype: `pika.frame.Method` having `method` attribute of type...
def queue_delete(self, queue='', if_unused=False, if_empty=False):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as delete_ok_result: self._impl.queue_delete(callback=delete_ok_result.set_value_once, queue=queue, if_unused=if_unused, if_empty=if_empty, nowait=False) self._flush_output(delete_ok_result.is_ready) return delete_ok_result.value.meth...
'Purge all of the messages from the specified queue :param queue: The queue to purge :type queue: str or unicode :returns: Method frame from the Queue.Purge-ok response :rtype: `pika.frame.Method` having `method` attribute of type `spec.Queue.PurgeOk`'
def queue_purge(self, queue=''):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as purge_ok_result: self._impl.queue_purge(callback=purge_ok_result.set_value_once, queue=queue, nowait=False) self._flush_output(purge_ok_result.is_ready) return purge_ok_result.value.method_frame
'Bind the queue to the specified exchange :param queue: The queue to bind to the exchange :type queue: str or unicode :param exchange: The source exchange to bind to :type exchange: str or unicode :param routing_key: The routing key to bind on :type routing_key: str or unicode :param dict arguments: Custom key/value pa...
def queue_bind(self, queue, exchange, routing_key=None, arguments=None):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as bind_ok_result: self._impl.queue_bind(callback=bind_ok_result.set_value_once, queue=queue, exchange=exchange, routing_key=routing_key, nowait=False, arguments=arguments) self._flush_output(bind_ok_result.is_ready) return bind_ok_re...
'Unbind a queue from an exchange. :param queue: The queue to unbind from the exchange :type queue: str or unicode :param exchange: The source exchange to bind from :type exchange: str or unicode :param routing_key: The routing key to unbind :type routing_key: str or unicode :param dict arguments: Custom key/value pair ...
def queue_unbind(self, queue='', exchange=None, routing_key=None, arguments=None):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as unbind_ok_result: self._impl.queue_unbind(callback=unbind_ok_result.set_value_once, queue=queue, exchange=exchange, routing_key=routing_key, arguments=arguments) self._flush_output(unbind_ok_result.is_ready) return unbind_ok_result...
'Select standard transaction mode. This method sets the channel to use standard transactions. The client must use this method at least once on a channel before using the Commit or Rollback methods. :returns: Method frame from the Tx.Select-ok response :rtype: `pika.frame.Method` having `method` attribute of type `spec....
def tx_select(self):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as select_ok_result: self._impl.tx_select(select_ok_result.set_value_once) self._flush_output(select_ok_result.is_ready) return select_ok_result.value.method_frame
'Commit a transaction. :returns: Method frame from the Tx.Commit-ok response :rtype: `pika.frame.Method` having `method` attribute of type `spec.Tx.CommitOk`'
def tx_commit(self):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as commit_ok_result: self._impl.tx_commit(commit_ok_result.set_value_once) self._flush_output(commit_ok_result.is_ready) return commit_ok_result.value.method_frame
'Rollback a transaction. :returns: Method frame from the Tx.Commit-ok response :rtype: `pika.frame.Method` having `method` attribute of type `spec.Tx.CommitOk`'
def tx_rollback(self):
with _CallbackResult(self._MethodFrameCallbackResultArgs) as rollback_ok_result: self._impl.tx_rollback(rollback_ok_result.set_value_once) self._flush_output(rollback_ok_result.is_ready) return rollback_ok_result.value.method_frame
'Create a heartbeat on connection sending a heartbeat frame every interval seconds. :param pika.connection.Connection: Connection object :param int interval: Heartbeat check interval :param int idle_count: Number of heartbeat intervals missed until the connection is considered idle and disconnects'
def __init__(self, connection, interval, idle_count=MAX_IDLE_COUNT):
self._connection = connection self._interval = interval self._max_idle_count = idle_count self._bytes_received = 0 self._bytes_sent = 0 self._heartbeat_frames_received = 0 self._heartbeat_frames_sent = 0 self._idle_byte_intervals = 0 self._timer = None self._setup_timer()
'Return True if the connection\'s heartbeat attribute is set to this instance. :rtype True'
@property def active(self):
return (self._connection.heartbeat is self)
'Return the number of bytes received by the connection bytes object. :rtype int'
@property def bytes_received_on_connection(self):
return self._connection.bytes_received
'Returns true if the byte count hasn\'t changed in enough intervals to trip the max idle threshold.'
@property def connection_is_idle(self):
return (self._idle_byte_intervals >= self._max_idle_count)
'Called when a heartbeat is received'
def received(self):
LOGGER.debug('Received heartbeat frame') self._heartbeat_frames_received += 1
'Invoked by a timer to send a heartbeat when we need to, check to see if we\'ve missed any heartbeats and disconnect our connection if it\'s been idle too long.'
def send_and_check(self):
LOGGER.debug('Received %i heartbeat frames, sent %i', self._heartbeat_frames_received, self._heartbeat_frames_sent) if self.connection_is_idle: return self._close_connection() if (not self._has_received_data): self._idle_byte_intervals += 1 else: self._idle_byte_in...
'Stop the heartbeat checker'
def stop(self):
if self._timer: LOGGER.debug('Removing timeout for next heartbeat interval') self._connection.remove_timeout(self._timer) self._timer = None
'Close the connection with the AMQP Connection-Forced value.'
def _close_connection(self):
LOGGER.info('Connection is idle, %i stale byte intervals', self._idle_byte_intervals) duration = (self._max_idle_count * self._interval) text = (HeartbeatChecker._STALE_CONNECTION % duration) self._connection.close(HeartbeatChecker._CONNECTION_FORCED, text) self._connection._on_ter...
'Returns True if the connection has received data on the connection. :rtype: bool'
@property def _has_received_data(self):
return (not (self._bytes_received == self.bytes_received_on_connection))
'Return a new heartbeat frame. :rtype pika.frame.Heartbeat'
@staticmethod def _new_heartbeat_frame():
return frame.Heartbeat()
'Send a heartbeat frame on the connection.'
def _send_heartbeat_frame(self):
LOGGER.debug('Sending heartbeat frame') self._connection._send_frame(self._new_heartbeat_frame()) self._heartbeat_frames_sent += 1
'Use the connection objects delayed_call function which is implemented by the Adapter for calling the check_heartbeats function every interval seconds.'
def _setup_timer(self):
self._timer = self._connection.add_timeout(self._interval, self.send_and_check)
'If the connection still has this object set for heartbeats, add a new timer.'
def _start_timer(self):
if self.active: self._setup_timer()
'Update the internal counters for bytes sent and received and the number of frames received'
def _update_counters(self):
self._bytes_sent = self._connection.bytes_sent self._bytes_received = self._connection.bytes_received
'Called when test times out'
def _on_test_timeout(self):
LOGGER.info('%s TIMED OUT (%s)', datetime.utcnow(), self) self.fail('Test timed out')
'BlockingConnection: Create and close connection'
def test(self):
connection = self._connect() self.assertIsInstance(connection, pika.BlockingConnection) self.assertTrue(connection.is_open) self.assertFalse(connection.is_closed) self.assertFalse(connection.is_closing) connection.close() self.assertTrue(connection.is_closed) self.assertFalse(connection....
'BlockingConnection: Close connection twice'
def test(self):
connection = self._connect() self.assertIsInstance(connection, pika.BlockingConnection) self.assertTrue(connection.is_open) self.assertFalse(connection.is_closed) self.assertFalse(connection.is_closing) connection.close() self.assertTrue(connection.is_closed) self.assertFalse(connection....
'BlockingConnection: connection context manager closes connection'
def test(self):
with self._connect() as connection: self.assertIsInstance(connection, pika.BlockingConnection) self.assertTrue(connection.is_open) self.assertTrue(connection.is_closed)
'BlockingConnection: connection context manager closes connection and passes original exception'
def test(self):
class MyException(Exception, ): pass with self.assertRaises(MyException): with self._connect() as connection: self.assertTrue(connection.is_open) raise MyException() self.assertTrue(connection.is_closed)
'BlockingConnection: connection context manager closes connection and passes system exception'
def test(self):
with self.assertRaises(SystemExit): with self._connect() as connection: self.assertTrue(connection.is_open) raise SystemExit() self.assertTrue(connection.is_closed)
'BlockingConnection: ConnectionClosed raised when creating exchange with invalid type'
def test(self):
connection = self._connect() ch = connection.channel() exg_name = ('TestInvalidExchangeTypeRaisesConnectionClosed_' + uuid.uuid1().hex) with self.assertRaises(pika.exceptions.ConnectionClosed) as ex_cm: ch.exchange_declare(exg_name, exchange_type='ZZwwInvalid') self.assertEqual(ex_cm.excepti...
'BlockingConnection: Create and close connection with channel and consumer'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestCreateAndCloseConnectionWithChannelAndConsumer_q' + uuid.uuid1().hex) body1 = ('a' * 1024) ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', ...
'BlockingConnection resets properly on TCP/IP drop during channel()'
def test(self):
with ForwardServer(remote_addr=(DEFAULT_PARAMS.host, DEFAULT_PARAMS.port), local_linger_args=(1, 0)) as fwd: self.connection = self._connect((PARAMS_URL_TEMPLATE % {'port': fwd.server_address[1]})) with self.assertRaises(pika.exceptions.ConnectionClosed): self.connection.channel() self.asser...
'BlockingConnection no access file descriptor after ConnectionClosed'
def test(self):
with ForwardServer(remote_addr=(DEFAULT_PARAMS.host, DEFAULT_PARAMS.port), local_linger_args=(1, 0)) as fwd: self.connection = self._connect((PARAMS_URL_TEMPLATE % {'port': fwd.server_address[1]})) with self.assertRaises(pika.exceptions.ConnectionClosed): self.connection.channel() self.asser...
'BlockingConnection to downed broker results in AMQPConnectionError'
def test(self):
sock = socket.socket() self.addCleanup(sock.close) sock.bind(('127.0.0.1', 0)) port = sock.getsockname()[1] sock.close() with self.assertRaises(pika.exceptions.AMQPConnectionError): self.connection = self._connect((PARAMS_URL_TEMPLATE % {'port': port}))
'BlockingConnection TCP/IP connection loss in CONNECTION_START'
def test(self):
fwd = ForwardServer(remote_addr=(DEFAULT_PARAMS.host, DEFAULT_PARAMS.port), local_linger_args=(1, 0)) fwd.start() self.addCleanup((lambda : (fwd.stop() if fwd.running else None))) class MySelectConnection(pika.SelectConnection, ): assert hasattr(pika.SelectConnection, '_on_connection_start') ...
'BlockingConnection TCP/IP connection loss in CONNECTION_TUNE'
def test(self):
fwd = ForwardServer(remote_addr=(DEFAULT_PARAMS.host, DEFAULT_PARAMS.port), local_linger_args=(1, 0)) fwd.start() self.addCleanup((lambda : (fwd.stop() if fwd.running else None))) class MySelectConnection(pika.SelectConnection, ): assert hasattr(pika.SelectConnection, '_on_connection_tune') ...
'BlockingConnection TCP/IP connection loss in CONNECTION_PROTOCOL'
def test(self):
fwd = ForwardServer(remote_addr=(DEFAULT_PARAMS.host, DEFAULT_PARAMS.port), local_linger_args=(1, 0)) fwd.start() self.addCleanup((lambda : (fwd.stop() if fwd.running else None))) class MySelectConnection(pika.SelectConnection, ): assert hasattr(pika.SelectConnection, '_on_connected') de...
'BlockingConnection.process_data_events'
def test(self):
connection = self._connect() start_time = time.time() connection.process_data_events(time_limit=0) elapsed = (time.time() - start_time) self.assertLess(elapsed, 0.25) start_time = time.time() connection.process_data_events(time_limit=0.005) elapsed = (time.time() - start_time) self.a...
'BlockingConnection register for Connection.Blocked/Unblocked'
def test(self):
connection = self._connect() connection.add_on_connection_blocked_callback((lambda frame: None)) blocked_buffer = [] evt = blocking_connection._ConnectionBlockedEvt((lambda f: blocked_buffer.append('blocked')), pika.frame.Method(1, pika.spec.Connection.Blocked('reason'))) repr(evt) evt.dispatch(...
'BlockingConnection Connection.Blocked timeout'
def test(self):
url = (DEFAULT_URL + '&blocked_connection_timeout=0.001') conn = self._connect(url=url) conn._impl._on_connection_blocked(pika.frame.Method(0, pika.spec.Connection.Blocked('TestBlockedConnectionTimeout'))) with self.assertRaises(pika.exceptions.ConnectionClosed) as excCtx: while True: ...
'BlockingConnection.add_timeout and remove_timeout'
def test(self):
connection = self._connect() start_time = time.time() rx_callback = [] timer_id = connection.add_timeout(0.005, (lambda : rx_callback.append(time.time()))) while (not rx_callback): connection.process_data_events(time_limit=None) self.assertEqual(len(rx_callback), 1) elapsed = (time.t...
'BlockingConnection.remove_timeout from timeout callback'
def test(self):
connection = self._connect() timer_id1 = connection.add_timeout(5, (lambda : (0 / 0))) rx_timer2 = [] def on_timer2(): connection.remove_timeout(timer_id1) connection.remove_timeout(timer_id2) rx_timer2.append(1) timer_id2 = connection.add_timeout(0, on_timer2) while (not...
'BlockingConnection.sleep'
def test(self):
connection = self._connect() start_time = time.time() connection.sleep(duration=0) elapsed = (time.time() - start_time) self.assertLess(elapsed, 0.25) start_time = time.time() connection.sleep(duration=0.005) elapsed = (time.time() - start_time) self.assertGreaterEqual(elapsed, 0.005...
'Test BlockingConnection properties'
def test(self):
connection = self._connect() self.assertTrue(connection.is_open) self.assertFalse(connection.is_closing) self.assertFalse(connection.is_closed) self.assertTrue(connection.basic_nack_supported) self.assertTrue(connection.consumer_cancel_notify_supported) self.assertTrue(connection.exchange_ex...
'BlockingChannel: Create and close channel'
def test(self):
connection = self._connect() ch = connection.channel() self.assertIsInstance(ch, blocking_connection.BlockingChannel) self.assertTrue(ch.is_open) self.assertFalse(ch.is_closed) self.assertFalse(ch.is_closing) self.assertIs(ch.connection, connection) ch.close() self.assertTrue(ch.is_c...
'BlockingChannel: Test exchange_declare and exchange_delete'
def test(self):
connection = self._connect() ch = connection.channel() name = ('TestExchangeDeclareAndDelete_' + uuid.uuid1().hex) frame = ch.exchange_declare(name, exchange_type='direct') self.addCleanup(connection.channel().exchange_delete, name) self.assertIsInstance(frame.method, pika.spec.Exchange.DeclareO...
'BlockingChannel: Test exchange_bind and exchange_unbind'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestExchangeBindAndUnbind_q' + uuid.uuid1().hex) src_exg_name = ('TestExchangeBindAndUnbind_src_exg_' + uuid.uuid1().hex) dest_exg_name = ('TestExchangeBindAndUnbind_dest_exg_' + uuid.uuid1().hex) routing_key = 'TestExchangeBindAn...
'BlockingChannel: Test queue_declare and queue_delete'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestQueueDeclareAndDelete_' + uuid.uuid1().hex) frame = ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) self.assertIsInstance(frame.method, pika.spec.Queue.DeclareOk) ...
'BlockingChannel: ChannelClosed raised when passive-declaring unknown queue'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestPassiveQueueDeclareOfUnknownQueueRaisesChannelClosed_q_' + uuid.uuid1().hex) with self.assertRaises(pika.exceptions.ChannelClosed) as ex_cm: ch.queue_declare(q_name, passive=True) self.assertEqual(ex_cm.exception.args[0], ...
'BlockingChannel: Test queue_bind and queue_unbind'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestQueueBindAndUnbindAndPurge_q' + uuid.uuid1().hex) exg_name = ('TestQueueBindAndUnbindAndPurge_exg_' + uuid.uuid1().hex) routing_key = 'TestQueueBindAndUnbindAndPurge' res = ch.confirm_delivery() self.assertIsNone(res) ...
'BlockingChannel.basic_get'
def test(self):
LOGGER.info('%s STARTED (%s)', datetime.utcnow(), self) connection = self._connect() LOGGER.info('%s CONNECTED (%s)', datetime.utcnow(), self) ch = connection.channel() LOGGER.info('%s CREATED CHANNEL (%s)', datetime.utcnow(), self) q_name = ('TestBasicGet_q' + uuid.uuid1()....
'BlockingChannel.basic_reject'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicReject_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', routing_key=q_name, body='TestBasi...
'BlockingChannel.basic_reject with requeue=False'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicRejectNoRequeue_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', routing_key=q_name, body=...
'BlockingChannel.basic_nack single message'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicNack_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', routing_key=q_name, body='TestBasicN...
'BlockingChannel.basic_nack with requeue=False'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicNackNoRequeue_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', routing_key=q_name, body='T...
'BlockingChannel.basic_nack multiple messages'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicNackMultiple_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', routing_key=q_name, body='Te...
'BlockingChannel.basic_recover with requeue=True. NOTE: the requeue=False option is not supported by RabbitMQ broker as of this writing (using RabbitMQ 3.5.1)'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicRecoverWithRequeue_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', routing_key=q_name, bo...
'BlockingChannel.tx_commit'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestTxCommit_q' + uuid.uuid1().hex) ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) frame = ch.tx_select() self.assertIsInstance(frame.method, pika.spec.Tx.SelectOk) ...
'BlockingChannel.tx_commit'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestTxRollback_q' + uuid.uuid1().hex) ch.queue_declare(q_name, auto_delete=True) self.addCleanup(self._connect().channel().queue_delete, q_name) frame = ch.tx_select() self.assertIsInstance(frame.method, pika.spec.Tx.SelectOk)...
'ChannelClosed raised when consuming from unknown queue'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicConsumeFromUnknownQueueRaisesChannelClosed_q_' + uuid.uuid1().hex) with self.assertRaises(pika.exceptions.ChannelClosed) as ex_cm: ch.basic_consume((lambda *args: None), q_name) self.assertEqual(ex_cm.exception.args[0...
'BlockingChannel.publish amd basic_publish unroutable message with pubacks'
def test(self):
connection = self._connect() ch = connection.channel() exg_name = ('TestPublishAndBasicPublishUnroutable_exg_' + uuid.uuid1().hex) routing_key = 'TestPublishAndBasicPublishUnroutable' res = ch.confirm_delivery() self.assertIsNone(res) ch.exchange_declare(exg_name, exchange_type='direct') ...
'BlockingChannel.confirm_delivery following unroutable message'
def test(self):
connection = self._connect() ch = connection.channel() exg_name = ('TestConfirmDeliveryAfterUnroutableMessage_exg_' + uuid.uuid1().hex) routing_key = 'TestConfirmDeliveryAfterUnroutableMessage' ch.exchange_declare(exg_name, exchange_type='direct') self.addCleanup(connection.channel().exchange_de...
'BlockingChannel: unroutable messages is returned in non-puback mode'
def test(self):
connection = self._connect() ch = connection.channel() exg_name = ('TestUnroutableMessageReturnedInNonPubackMode_exg_' + uuid.uuid1().hex) routing_key = 'TestUnroutableMessageReturnedInNonPubackMode' ch.exchange_declare(exg_name, exchange_type='direct') self.addCleanup(connection.channel().excha...
'BlockingChannel: unroutable messages is returned in puback mode'
def test(self):
connection = self._connect() ch = connection.channel() exg_name = ('TestUnroutableMessageReturnedInPubackMode_exg_' + uuid.uuid1().hex) routing_key = 'TestUnroutableMessageReturnedInPubackMode' ch.exchange_declare(exg_name, exchange_type='direct') self.addCleanup(connection.channel().exchange_de...
'BlockingChannel.basic_publish msg delivered despite pending unroutable message'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicPublishDeliveredWhenPendingUnroutable_q' + uuid.uuid1().hex) exg_name = ('TestBasicPublishDeliveredWhenPendingUnroutable_exg_' + uuid.uuid1().hex) routing_key = 'TestBasicPublishDeliveredWhenPendingUnroutable' ch.exchange...
'BlockingChannel.basic_publish, publish, basic_consume, QoS, Basic.Cancel from broker'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestPublishAndConsumeAndQos_q' + uuid.uuid1().hex) exg_name = ('TestPublishAndConsumeAndQos_exg_' + uuid.uuid1().hex) routing_key = 'TestPublishAndConsumeAndQos' res = ch.confirm_delivery() self.assertIsNone(res) ch.exchan...
'BlockingChannel: two basic_consume consumers on same channel'
def test(self):
connection = self._connect() ch = connection.channel() exg_name = ('TestPublishAndConsumeAndQos_exg_' + uuid.uuid1().hex) q1_name = ('TestTwoBasicConsumersOnSameChannel_q1' + uuid.uuid1().hex) q2_name = ('TestTwoBasicConsumersOnSameChannel_q2' + uuid.uuid1().hex) q1_routing_key = 'TestTwoBasicCo...
'BlockingChannel.basic_cancel purges pending _ConsumerCancellationEvt'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicCancelPurgesPendingConsumerCancellationEvt_q' + uuid.uuid1().hex) ch.queue_declare(q_name) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish('', routing_key=q_name, body='via-publish', mandatory=T...
'BlockingChannel.basic_publish without pubacks'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicPublishWithoutPubacks_q' + uuid.uuid1().hex) exg_name = ('TestBasicPublishWithoutPubacks_exg_' + uuid.uuid1().hex) routing_key = 'TestBasicPublishWithoutPubacks' ch.exchange_declare(exg_name, exchange_type='direct') s...
'BlockingChannel.basic_publish from basic_consume callback'
def test(self):
connection = self._connect() ch = connection.channel() src_q_name = ('TestPublishFromBasicConsumeCallback_src_q' + uuid.uuid1().hex) dest_q_name = ('TestPublishFromBasicConsumeCallback_dest_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(src_q_name, auto_delete=True) self.addCl...
'BlockingChannel.stop_consuming from basic_consume callback'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestStopConsumingFromBasicConsumeCallback_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=False) self.addCleanup(connection.channel().queue_delete, q_name) ch.publish('', routing_key=q_name, b...
'BlockingChannel.close from basic_consume callback'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestCloseChannelFromBasicConsumeCallback_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=False) self.addCleanup(connection.channel().queue_delete, q_name) ch.publish('', routing_key=q_name, bo...
'BlockingConnection.close from basic_consume callback'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestCloseConnectionFromBasicConsumeCallback_q' + uuid.uuid1().hex) ch.confirm_delivery() ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish('', routing_key=q_...
'BlockingChannel.publish/consume huge message'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestPublishAndConsumeHugeMessage_q' + uuid.uuid1().hex) body = ('a' * 1000000) ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exchange='', routing_key=q_n...
'BlockingChannel non-pub-ack publish/consume many messages'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestNonPubackPublishAndConsumeManyMessages_q' + uuid.uuid1().hex) body = ('b' * 1024) num_messages_to_publish = 500 ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) ...
'BlockingChannel user cancels non-ackable consumer via basic_cancel'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicCancelWithNonAckableConsumer_q' + uuid.uuid1().hex) body1 = ('a' * 1024) body2 = ('b' * 2048) ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(...
'BlockingChannel user cancels ackable consumer via basic_cancel'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestBasicCancelWithAckableConsumer_q' + uuid.uuid1().hex) body1 = ('a' * 1024) body2 = ('b' * 2048) ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) ch.publish(exc...
'BlockingChannel unacked message restored to q on channel close'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestUnackedMessageAutoRestoredToQueueOnChannelClose_q' + uuid.uuid1().hex) body1 = ('a' * 1024) body2 = ('b' * 2048) ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) ...
'BlockingChannel unacked message restored to q on channel close'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestNoAckMessageNotRestoredToQueueOnChannelClose_q' + uuid.uuid1().hex) body1 = ('a' * 1024) body2 = ('b' * 2048) ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) ...
'BlockingChannel Channel.Flow activate and deactivate'
def test(self):
connection = self._connect() ch = connection.channel() q_name = ('TestChannelFlow_q' + uuid.uuid1().hex) ch.queue_declare(q_name, auto_delete=False) self.addCleanup(self._connect().channel().queue_delete, q_name) frame = ch.queue_declare(q_name, passive=True) self.assertEqual(frame.method.co...
':param tuple remote_addr: remote server\'s IP address, whose structure depends on remote_addr_family; pair (host-or-ip-addr, port-number). Pass None to have ForwardServer behave as echo server. :param remote_addr_family: socket.AF_INET (the default), socket.AF_INET6 or socket.AF_UNIX. :param remote_socket_type: only s...
def __init__(self, remote_addr, remote_addr_family=socket.AF_INET, remote_socket_type=socket.SOCK_STREAM, server_addr=('127.0.0.1', 0), server_addr_family=socket.AF_INET, server_socket_type=socket.SOCK_STREAM, local_linger_args=None):
self._logger = logging.getLogger(__name__) self._remote_addr = remote_addr self._remote_addr_family = remote_addr_family assert (remote_socket_type == socket.SOCK_STREAM), remote_socket_type self._remote_socket_type = remote_socket_type assert (server_addr is not None) self._server_addr = se...
'Property: True if ForwardServer is active'
@property def running(self):
return (self._subproc is not None)
'Property: Get listening socket\'s address family NOTE: undefined before server starts and after it shuts down'
@property def server_address_family(self):
assert (self._server_addr_family is not None), 'Not in context' return self._server_addr_family
'Property: Get listening socket\'s address; the returned value depends on the listening socket\'s address family NOTE: undefined before server starts and after it shuts down'
@property def server_address(self):
assert (self._server_addr is not None), 'Not in context' return self._server_addr
'Context manager entry. Starts the forwarding server :returns: self'
def __enter__(self):
return self.start()
'Context manager exit; stops the forwarding server'
def __exit__(self, *args):
self.stop()
'Start the server NOTE: The context manager is the recommended way to use ForwardServer. start()/stop() are alternatives to the context manager use case and are mutually exclusive with it. :returns: self'
def start(self):
queue = multiprocessing.Queue() self._subproc = multiprocessing.Process(target=_run_server, kwargs=dict(local_addr=self._server_addr, local_addr_family=self._server_addr_family, local_socket_type=self._server_socket_type, local_linger_args=self._local_linger_args, remote_addr=self._remote_addr, remote_addr_fami...
'Stop the server NOTE: The context manager is the recommended way to use ForwardServer. start()/stop() are alternatives to the context manager use case and are mutually exclusive with it.'
def stop(self):
self._logger.info('ForwardServer STOPPING') try: self._subproc.terminate() self._subproc.join(timeout=self._SUBPROC_TIMEOUT) if self._subproc.is_alive(): self._logger.error('ForwardServer failed to terminate, killing it') os.kill(self._subproc.pi...
':param request: for super :param client_address: for super "paarm server: for super :param tuple local_linger_args: SO_LINGER sockoverride for the local connection sockets, to be configured after connection is accepted. Pass None to not change SO_LINGER. Otherwise, its a two-tuple, where the first element is the `l_o...
def __init__(self, request, client_address, server, local_linger_args, remote_addr, remote_addr_family, remote_socket_type):
self._local_linger_args = local_linger_args self._remote_addr = remote_addr self._remote_addr_family = remote_addr_family self._remote_socket_type = remote_socket_type super(_TCPHandler, self).__init__(request=request, client_address=client_address, server=server)
'Connect to remote and forward data between local and remote'
def handle(self):
local_sock = self.connection if (self._local_linger_args is not None): (l_onoff, l_linger) = self._local_linger_args local_sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', l_onoff, l_linger)) if (self._remote_addr is not None): remote_dest_sock = remote_src_sock...
'Forward from src_sock to dest_sock'
def _forward(self, src_sock, dest_sock):
src_peername = src_sock.getpeername() _trace('%s forwarding from %s to %s', datetime.utcnow(), src_peername, dest_sock.getpeername()) try: rx_buf = array.array('B', ([0] * self._SOCK_RX_BUF_SIZE)) while True: try: nbytes = src_sock.recv_into(rx_buf)...