desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Return a result until we get a reply with an \'ending" flag'
| def __iter__(self):
| if self._done:
raise StopIteration
while True:
try:
data = self._dataqueue.get(timeout=self._timeout)
result = self._process_data(data)
except queue.Empty:
LOG.exception(_('Timed out waiting for RPC response.'))
self.done()
... |
'The consume() callback will call this. Store the result.'
| def __call__(self, data):
| self.msg_id_cache.check_duplicate_message(data)
if data['failure']:
failure = data['failure']
self._result = rpc_common.deserialize_remote_exception(self._conf, failure)
elif data.get('ending', False):
self._got_ending = True
else:
self._result = data['result']
|
'Return a result until we get a \'None\' response from consumer'
| def __iter__(self):
| if self._done:
raise StopIteration
while True:
try:
self._iterator.next()
except Exception:
with excutils.save_and_reraise_exception():
self.done()
if self._got_ending:
self.done()
raise StopIteration
result ... |
'Initialize the rpc dispatcher.
:param callbacks: List of proxy objects that are an instance
of a class with rpc methods exposed. Each proxy
object should have an RPC_API_VERSION attribute.'
| def __init__(self, callbacks):
| self.callbacks = callbacks
super(RpcDispatcher, self).__init__()
|
'Dispatch a message based on a requested version.
:param ctxt: The request context
:param version: The requested API version from the incoming message
:param method: The method requested to be called by the incoming
message.
:param kwargs: A dict of keyword arguments to be passed to the method.
:returns: Whatever is re... | def dispatch(self, ctxt, version, method, **kwargs):
| if (not version):
version = '1.0'
had_compatible = False
for proxyobj in self.callbacks:
if hasattr(proxyobj, 'RPC_API_VERSION'):
rpc_api_version = proxyobj.RPC_API_VERSION
else:
rpc_api_version = '1.0'
is_compatible = rpc_common.version_is_compatible(... |
'Register a host on a backend.
Heartbeats, if applicable, may keepalive registration.'
| def register(self, key, host):
| pass
|
'Acknowledge that a key.host is alive.
Used internally for updating heartbeats,
but may also be used publically to acknowledge
a system is alive (i.e. rpc message successfully
sent to host)'
| def ack_alive(self, key, host):
| pass
|
'Checks if a host is alive.'
| def is_alive(self, topic, host):
| pass
|
'Explicitly expire a host\'s registration.'
| def expire(self, topic, host):
| pass
|
'Send all heartbeats.
Use start_heartbeat to spawn a heartbeat greenthread,
which loops this method.'
| def send_heartbeats(self):
| pass
|
'Unregister a topic.'
| def unregister(self, key, host):
| pass
|
'Spawn heartbeat greenthread.'
| def start_heartbeat(self):
| pass
|
'Destroys the heartbeat greenthread.'
| def stop_heartbeat(self):
| pass
|
'Send all heartbeats.
Use start_heartbeat to spawn a heartbeat greenthread,
which loops this method.'
| def send_heartbeats(self):
| for (key, host) in self.host_topic:
self.ack_alive(key, host)
|
'Acknowledge that a host.topic is alive.
Used internally for updating heartbeats,
but may also be used publically to acknowledge
a system is alive (i.e. rpc message successfully
sent to host)'
| def ack_alive(self, key, host):
| raise NotImplementedError('Must implement ack_alive')
|
'Implements registration logic.
Called by register(self,key,host)'
| def backend_register(self, key, host):
| raise NotImplementedError('Must implement backend_register')
|
'Implements de-registration logic.
Called by unregister(self,key,host)'
| def backend_unregister(self, key, key_host):
| raise NotImplementedError('Must implement backend_unregister')
|
'Register a host on a backend.
Heartbeats, if applicable, may keepalive registration.'
| def register(self, key, host):
| self.hosts.add(host)
self.host_topic[(key, host)] = host
key_host = '.'.join((key, host))
self.backend_register(key, key_host)
self.ack_alive(key, host)
|
'Unregister a topic.'
| def unregister(self, key, host):
| if ((key, host) in self.host_topic):
del self.host_topic[(key, host)]
self.hosts.discard(host)
self.backend_unregister(key, '.'.join((key, host)))
LOG.info(_(('Matchmaker unregistered: %s, %s' % (key, host))))
|
'Implementation of MatchMakerBase.start_heartbeat
Launches greenthread looping send_heartbeats(),
yielding for CONF.matchmaker_heartbeat_freq seconds
between iterations.'
| def start_heartbeat(self):
| if (len(self.hosts) == 0):
raise MatchMakerException(_('Register before starting heartbeat.'))
def do_heartbeat():
while True:
self.send_heartbeats()
eventlet.sleep(CONF.matchmaker_heartbeat_freq)
self._heart = eventlet.spawn(do_heartbeat)
|
'Destroys the heartbeat greenthread.'
| def stop_heartbeat(self):
| if self._heart:
self._heart.kill()
|
'Declare a queue on an amqp session.
\'session\' is the amqp session to use
\'callback\' is the callback to call when messages are received
\'node_name\' is the first part of the Qpid address string, before \';\'
\'node_opts\' will be applied to the "x-declare" section of "node"
in the address string.
\'link_name\' goe... | def __init__(self, session, callback, node_name, node_opts, link_name, link_opts):
| self.callback = callback
self.receiver = None
self.session = None
addr_opts = {'create': 'always', 'node': {'type': 'topic', 'x-declare': {'durable': True, 'auto-delete': True}}, 'link': {'name': link_name, 'durable': True, 'x-declare': {'durable': False, 'auto-delete': True, 'exclusive': False}}}
a... |
'Re-declare the receiver after a qpid reconnect'
| def reconnect(self, session):
| self.session = session
self.receiver = session.receiver(self.address)
self.receiver.capacity = 1
|
'Fetch the message and pass it to the callback object'
| def consume(self):
| message = self.receiver.fetch()
try:
msg = rpc_common.deserialize_msg(message.content)
self.callback(msg)
except Exception:
LOG.exception(_('Failed to process message... skipping it.'))
finally:
self.session.acknowledge(message)
|
'Init a \'direct\' queue.
\'session\' is the amqp session to use
\'msg_id\' is the msg_id to listen on
\'callback\' is the callback to call when messages are received'
| def __init__(self, conf, session, msg_id, callback):
| super(DirectConsumer, self).__init__(session, callback, ('%s/%s' % (msg_id, msg_id)), {'type': 'direct'}, msg_id, {'exclusive': True})
|
'Init a \'topic\' queue.
:param session: the amqp session to use
:param topic: is the topic to listen on
:paramtype topic: str
:param callback: the callback to call when messages are received
:param name: optional queue name, defaults to topic'
| def __init__(self, conf, session, topic, callback, name=None, exchange_name=None):
| exchange_name = (exchange_name or rpc_amqp.get_control_exchange(conf))
super(TopicConsumer, self).__init__(session, callback, ('%s/%s' % (exchange_name, topic)), {}, (name or topic), {})
|
'Init a \'fanout\' queue.
\'session\' is the amqp session to use
\'topic\' is the topic to listen on
\'callback\' is the callback to call when messages are received'
| def __init__(self, conf, session, topic, callback):
| super(FanoutConsumer, self).__init__(session, callback, ('%s_fanout' % topic), {'durable': False, 'type': 'fanout'}, ('%s_fanout_%s' % (topic, uuid.uuid4().hex)), {'exclusive': True})
|
'Init the Publisher class with the exchange_name, routing_key,
and other options'
| def __init__(self, session, node_name, node_opts=None):
| self.sender = None
self.session = session
addr_opts = {'create': 'always', 'node': {'type': 'topic', 'x-declare': {'durable': False, 'auto-delete': True}}}
if node_opts:
addr_opts['node']['x-declare'].update(node_opts)
self.address = ('%s ; %s' % (node_name, jsonutils.dumps(addr_opts))... |
'Re-establish the Sender after a reconnection'
| def reconnect(self, session):
| self.sender = session.sender(self.address)
|
'Send a message'
| def send(self, msg):
| self.sender.send(msg)
|
'Init a \'direct\' publisher.'
| def __init__(self, conf, session, msg_id):
| super(DirectPublisher, self).__init__(session, msg_id, {'type': 'Direct'})
|
'init a \'topic\' publisher.'
| def __init__(self, conf, session, topic):
| exchange_name = rpc_amqp.get_control_exchange(conf)
super(TopicPublisher, self).__init__(session, ('%s/%s' % (exchange_name, topic)))
|
'init a \'fanout\' publisher.'
| def __init__(self, conf, session, topic):
| super(FanoutPublisher, self).__init__(session, ('%s_fanout' % topic), {'type': 'fanout'})
|
'init a \'topic\' publisher.'
| def __init__(self, conf, session, topic):
| exchange_name = rpc_amqp.get_control_exchange(conf)
super(NotifyPublisher, self).__init__(session, ('%s/%s' % (exchange_name, topic)), {'durable': True})
|
'Handles reconnecting and re-establishing sessions and queues'
| def reconnect(self):
| if self.connection.opened():
try:
self.connection.close()
except qpid_exceptions.ConnectionError:
pass
attempt = 0
delay = 1
while True:
broker = self.brokers[(attempt % len(self.brokers))]
attempt += 1
try:
self.connection_crea... |
'Close/release this connection'
| def close(self):
| self.cancel_consumer_thread()
self.wait_on_proxy_callbacks()
self.connection.close()
self.connection = None
|
'Reset a connection so it can be used again'
| def reset(self):
| self.cancel_consumer_thread()
self.wait_on_proxy_callbacks()
self.session.close()
self.session = self.connection.session()
self.consumers = {}
|
'Create a Consumer using the class that was passed in and
add it to our list of consumers'
| def declare_consumer(self, consumer_cls, topic, callback):
| def _connect_error(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
LOG.error((_("Failed to declare consumer for topic '%(topic)s': %(err_str)s") % log_info))
def _declare_consumer():
consumer = consumer_cls(self.conf, self.session, topic, callback)
sel... |
'Return an iterator that will consume from all queues/consumers'
| def iterconsume(self, limit=None, timeout=None):
| def _error_callback(exc):
if isinstance(exc, qpid_exceptions.Empty):
LOG.debug((_('Timed out waiting for RPC response: %s') % str(exc)))
raise rpc_common.Timeout()
else:
LOG.exception((_('Failed to consume message from queue: %s... |
'Cancel a consumer thread'
| def cancel_consumer_thread(self):
| if (self.consumer_thread is not None):
self.consumer_thread.kill()
try:
self.consumer_thread.wait()
except greenlet.GreenletExit:
pass
self.consumer_thread = None
|
'Wait for all proxy callback threads to exit.'
| def wait_on_proxy_callbacks(self):
| for proxy_cb in self.proxy_callbacks:
proxy_cb.wait()
|
'Send to a publisher based on the publisher class'
| def publisher_send(self, cls, topic, msg):
| def _connect_error(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
LOG.exception((_("Failed to publish message to topic '%(topic)s': %(err_str)s") % log_info))
def _publisher_send():
publisher = cls(self.conf, self.session, topic)
publisher.send(msg)
... |
'Create a \'direct\' queue.
In nova\'s use, this is generally a msg_id queue used for
responses for call/multicall'
| def declare_direct_consumer(self, topic, callback):
| self.declare_consumer(DirectConsumer, topic, callback)
|
'Create a \'topic\' consumer.'
| def declare_topic_consumer(self, topic, callback=None, queue_name=None, exchange_name=None):
| self.declare_consumer(functools.partial(TopicConsumer, name=queue_name, exchange_name=exchange_name), topic, callback)
|
'Create a \'fanout\' consumer'
| def declare_fanout_consumer(self, topic, callback):
| self.declare_consumer(FanoutConsumer, topic, callback)
|
'Send a \'direct\' message'
| def direct_send(self, msg_id, msg):
| self.publisher_send(DirectPublisher, msg_id, msg)
|
'Send a \'topic\' message'
| def topic_send(self, topic, msg, timeout=None):
| qpid_message = qpid_messaging.Message(content=msg, ttl=timeout)
self.publisher_send(TopicPublisher, topic, qpid_message)
|
'Send a \'fanout\' message'
| def fanout_send(self, topic, msg):
| self.publisher_send(FanoutPublisher, topic, msg)
|
'Send a notify message on a topic'
| def notify_send(self, topic, msg, **kwargs):
| self.publisher_send(NotifyPublisher, topic, msg)
|
'Consume from all queues/consumers'
| def consume(self, limit=None):
| it = self.iterconsume(limit=limit)
while True:
try:
it.next()
except StopIteration:
return
|
'Consumer from all queues/consumers in a greenthread'
| def consume_in_thread(self):
| def _consumer_thread():
try:
self.consume()
except greenlet.GreenletExit:
return
if (self.consumer_thread is None):
self.consumer_thread = eventlet.spawn(_consumer_thread)
return self.consumer_thread
|
'Create a consumer that calls a method in a proxy object'
| def create_consumer(self, topic, proxy, fanout=False):
| proxy_cb = rpc_amqp.ProxyCallback(self.conf, proxy, rpc_amqp.get_connection_pool(self.conf, Connection))
self.proxy_callbacks.append(proxy_cb)
if fanout:
consumer = FanoutConsumer(self.conf, self.session, topic, proxy_cb)
else:
consumer = TopicConsumer(self.conf, self.session, topic, pro... |
'Create a worker that calls a method in a proxy object'
| def create_worker(self, topic, proxy, pool_name):
| proxy_cb = rpc_amqp.ProxyCallback(self.conf, proxy, rpc_amqp.get_connection_pool(self.conf, Connection))
self.proxy_callbacks.append(proxy_cb)
consumer = TopicConsumer(self.conf, self.session, topic, proxy_cb, name=pool_name)
self._register_consumer(consumer)
return consumer
|
'Register as a member of a group of consumers for a given topic from
the specified exchange.
Exactly one member of a given pool will receive each message.
A message will be delivered to multiple pools, if more than
one is created.'
| def join_consumer_pool(self, callback, pool_name, topic, exchange_name=None):
| callback_wrapper = rpc_amqp.CallbackWrapper(conf=self.conf, callback=callback, connection_pool=rpc_amqp.get_connection_pool(self.conf, Connection))
self.proxy_callbacks.append(callback_wrapper)
consumer = TopicConsumer(conf=self.conf, session=self.session, topic=topic, callback=callback_wrapper, name=pool_n... |
'Get socket type as string.'
| def socket_s(self):
| t_enum = ('PUSH', 'PULL', 'PUB', 'SUB', 'REP', 'REQ', 'ROUTER', 'DEALER')
return dict(map((lambda t: (getattr(zmq, t), t)), t_enum))[self.type]
|
'Subscribe.'
| def subscribe(self, msg_filter):
| if (not self.can_sub):
raise RPCException('Cannot subscribe on this socket.')
LOG.debug(_('Subscribing to %s'), msg_filter)
try:
self.sock.setsockopt(zmq.SUBSCRIBE, msg_filter)
except Exception:
return
self.subscriptions.append(msg_filter)
|
'Unsubscribe.'
| def unsubscribe(self, msg_filter):
| if (msg_filter not in self.subscriptions):
return
self.sock.setsockopt(zmq.UNSUBSCRIBE, msg_filter)
self.subscriptions.remove(msg_filter)
|
'Process a curried message and cast the result to topic.'
| def _get_response(self, ctx, proxy, topic, data):
| LOG.debug(_('Running func with context: %s'), ctx.to_dict())
data.setdefault('version', None)
data.setdefault('args', {})
try:
result = proxy.dispatch(ctx, data['version'], data['method'], **data['args'])
return ConsumerBase.normalize_reply(result, ctx.replies)
except gre... |
'Reply to a casted call.'
| def reply(self, ctx, proxy, msg_id=None, context=None, topic=None, msg=None):
| child_ctx = RpcContext.unmarshal(msg[0])
response = ConsumerBase.normalize_reply(self._get_response(child_ctx, proxy, topic, msg[1]), ctx.replies)
LOG.debug(_('Sending reply'))
_multi_send(_cast, ctx, topic, {'method': '-process_reply', 'args': {'msg_id': msg_id, 'response': response}}, _msg_id=msg_i... |
'Runs the ZmqProxy service'
| def consume_in_thread(self):
| ipc_dir = CONF.rpc_zmq_ipc_dir
consume_in = ('tcp://%s:%s' % (CONF.rpc_zmq_bind_address, CONF.rpc_zmq_port))
consumption_proxy = InternalContext(None)
if (not os.path.isdir(ipc_dir)):
try:
utils.execute('mkdir', '-p', ipc_dir, run_as_root=True)
utils.execute('chown', ('%s... |
'Close the connection.
This method must be called when the connection will no longer be used.
It will ensure that any resources associated with the connection, such
as a network connection, and cleaned up.'
| def close(self):
| raise NotImplementedError()
|
'Create a consumer on this connection.
A consumer is associated with a message queue on the backend message
bus. The consumer will read messages from the queue, unpack them, and
dispatch them to the proxy object. The contents of the message pulled
off of the queue will determine which method gets called on the proxy
... | def create_consumer(self, topic, proxy, fanout=False):
| raise NotImplementedError()
|
'Create a worker on this connection.
A worker is like a regular consumer of messages directed to a
topic, except that it is part of a set of such consumers (the
"pool") which may run in parallel. Every pool of workers will
receive a given message, but only one worker in the pool will
be asked to process it. Load is dis... | def create_worker(self, topic, proxy, pool_name):
| raise NotImplementedError()
|
'Register as a member of a group of consumers for a given topic from
the specified exchange.
Exactly one member of a given pool will receive each message.
A message will be delivered to multiple pools, if more than
one is created.
:param callback: Callable to be invoked for each message.
:type callback: callable accept... | def join_consumer_pool(self, callback, pool_name, topic, exchange_name):
| raise NotImplementedError()
|
'Spawn a thread to handle incoming messages.
Spawn a thread that will be responsible for handling all incoming
messages for consumers that were set up on this connection.
Message dispatching inside of this is expected to be implemented in a
non-blocking manner. An example implementation would be having this
thread pul... | def consume_in_thread(self):
| raise NotImplementedError()
|
'Return a version of this context with admin flag set.'
| def elevated(self, read_deleted=None, overwrite=False):
| context = self.deepcopy()
context.values['is_admin'] = True
context.values.setdefault('roles', [])
if ('admin' not in context.values['roles']):
context.values['roles'].append('admin')
if (read_deleted is not None):
context.values['read_deleted'] = read_deleted
return context
|
'Declare a queue on an amqp channel.
\'channel\' is the amqp channel to use
\'callback\' is the callback to call when messages are received
\'tag\' is a unique ID for the consumer on the channel
queue name, exchange name, and other kombu options are
passed in here as a dictionary.'
| def __init__(self, channel, callback, tag, **kwargs):
| self.callback = callback
self.tag = str(tag)
self.kwargs = kwargs
self.queue = None
self.reconnect(channel)
|
'Re-declare the queue after a rabbit reconnect'
| def reconnect(self, channel):
| self.channel = channel
self.kwargs['channel'] = channel
self.queue = kombu.entity.Queue(**self.kwargs)
self.queue.declare()
|
'Actually declare the consumer on the amqp channel. This will
start the flow of messages from the queue. Using the
Connection.iterconsume() iterator will process the messages,
calling the appropriate callback.
If a callback is specified in kwargs, use that. Otherwise,
use the callback passed during __init__()
If kwa... | def consume(self, *args, **kwargs):
| options = {'consumer_tag': self.tag}
options['nowait'] = kwargs.get('nowait', False)
callback = kwargs.get('callback', self.callback)
if (not callback):
raise ValueError('No callback defined')
def _callback(raw_message):
message = self.channel.message_to_python(raw_message)
... |
'Cancel the consuming from the queue, if it has started'
| def cancel(self):
| try:
self.queue.cancel(self.tag)
except KeyError as e:
if (str(e) != ("u'%s'" % self.tag)):
raise
self.queue = None
|
'Init a \'direct\' queue.
\'channel\' is the amqp channel to use
\'msg_id\' is the msg_id to listen on
\'callback\' is the callback to call when messages are received
\'tag\' is a unique ID for the consumer on the channel
Other kombu options may be passed'
| def __init__(self, conf, channel, msg_id, callback, tag, **kwargs):
| options = {'durable': False, 'queue_arguments': _get_queue_arguments(conf), 'auto_delete': True, 'exclusive': False}
options.update(kwargs)
exchange = kombu.entity.Exchange(name=msg_id, type='direct', durable=options['durable'], auto_delete=options['auto_delete'])
super(DirectConsumer, self).__init__(ch... |
'Init a \'topic\' queue.
:param channel: the amqp channel to use
:param topic: the topic to listen on
:paramtype topic: str
:param callback: the callback to call when messages are received
:param tag: a unique ID for the consumer on the channel
:param name: optional queue name, defaults to topic
:paramtype name: str
Ot... | def __init__(self, conf, channel, topic, callback, tag, name=None, exchange_name=None, **kwargs):
| options = {'durable': conf.rabbit_durable_queues, 'queue_arguments': _get_queue_arguments(conf), 'auto_delete': False, 'exclusive': False}
options.update(kwargs)
exchange_name = (exchange_name or rpc_amqp.get_control_exchange(conf))
exchange = kombu.entity.Exchange(name=exchange_name, type='topic', dura... |
'Init a \'fanout\' queue.
\'channel\' is the amqp channel to use
\'topic\' is the topic to listen on
\'callback\' is the callback to call when messages are received
\'tag\' is a unique ID for the consumer on the channel
Other kombu options may be passed'
| def __init__(self, conf, channel, topic, callback, tag, **kwargs):
| unique = uuid.uuid4().hex
exchange_name = ('%s_fanout' % topic)
queue_name = ('%s_fanout_%s' % (topic, unique))
options = {'durable': False, 'queue_arguments': _get_queue_arguments(conf), 'auto_delete': True, 'exclusive': False}
options.update(kwargs)
exchange = kombu.entity.Exchange(name=exchan... |
'Init the Publisher class with the exchange_name, routing_key,
and other options'
| def __init__(self, channel, exchange_name, routing_key, **kwargs):
| self.exchange_name = exchange_name
self.routing_key = routing_key
self.kwargs = kwargs
self.reconnect(channel)
|
'Re-establish the Producer after a rabbit reconnection'
| def reconnect(self, channel):
| self.exchange = kombu.entity.Exchange(name=self.exchange_name, **self.kwargs)
self.producer = kombu.messaging.Producer(exchange=self.exchange, channel=channel, routing_key=self.routing_key)
|
'Send a message'
| def send(self, msg, timeout=None):
| if timeout:
self.producer.publish(msg, headers={'ttl': (timeout * 1000)})
else:
self.producer.publish(msg)
|
'init a \'direct\' publisher.
Kombu options may be passed as keyword args to override defaults'
| def __init__(self, conf, channel, msg_id, **kwargs):
| options = {'durable': False, 'auto_delete': True, 'exclusive': False}
options.update(kwargs)
super(DirectPublisher, self).__init__(channel, msg_id, msg_id, type='direct', **options)
|
'init a \'topic\' publisher.
Kombu options may be passed as keyword args to override defaults'
| def __init__(self, conf, channel, topic, **kwargs):
| options = {'durable': conf.rabbit_durable_queues, 'auto_delete': False, 'exclusive': False}
options.update(kwargs)
exchange_name = rpc_amqp.get_control_exchange(conf)
super(TopicPublisher, self).__init__(channel, exchange_name, topic, type='topic', **options)
|
'init a \'fanout\' publisher.
Kombu options may be passed as keyword args to override defaults'
| def __init__(self, conf, channel, topic, **kwargs):
| options = {'durable': False, 'auto_delete': True, 'exclusive': False}
options.update(kwargs)
super(FanoutPublisher, self).__init__(channel, ('%s_fanout' % topic), None, type='fanout', **options)
|
'Handles fetching what ssl params
should be used for the connection (if any)'
| def _fetch_ssl_params(self):
| ssl_params = dict()
if self.conf.kombu_ssl_version:
ssl_params['ssl_version'] = self.conf.kombu_ssl_version
if self.conf.kombu_ssl_keyfile:
ssl_params['keyfile'] = self.conf.kombu_ssl_keyfile
if self.conf.kombu_ssl_certfile:
ssl_params['certfile'] = self.conf.kombu_ssl_certfile
... |
'Connect to rabbit. Re-establish any queues that may have
been declared before if we are reconnecting. Exceptions should
be handled by the caller.'
| def _connect(self, params):
| if self.connection:
LOG.info((_('Reconnecting to AMQP server on %(hostname)s:%(port)d') % params))
try:
self.connection.release()
except self.connection_errors:
pass
self.connection = None
self.connection = kombu.connection.BrokerConnection(... |
'Handles reconnecting and re-establishing queues.
Will retry up to self.max_retries number of times.
self.max_retries = 0 means to retry forever.
Sleep between tries, starting at self.interval_start
seconds, backing off self.interval_stepping number of seconds
each attempt.'
| def reconnect(self):
| attempt = 0
while True:
params = self.params_list[(attempt % len(self.params_list))]
attempt += 1
try:
self._connect(params)
return
except (IOError, self.connection_errors) as e:
pass
except Exception as e:
if ('timeout' not... |
'Convenience call for bin/clear_rabbit_queues'
| def get_channel(self):
| return self.channel
|
'Close/release this connection'
| def close(self):
| self.cancel_consumer_thread()
self.wait_on_proxy_callbacks()
self.connection.release()
self.connection = None
|
'Reset a connection so it can be used again'
| def reset(self):
| self.cancel_consumer_thread()
self.wait_on_proxy_callbacks()
self.channel.close()
self.channel = self.connection.channel()
if self.memory_transport:
self.channel._new_queue('ae.undeliver')
self.consumers = []
|
'Create a Consumer using the class that was passed in and
add it to our list of consumers'
| def declare_consumer(self, consumer_cls, topic, callback):
| def _connect_error(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
LOG.error((_("Failed to declare consumer for topic '%(topic)s': %(err_str)s") % log_info))
def _declare_consumer():
consumer = consumer_cls(self.conf, self.channel, topic, callback, self.consum... |
'Return an iterator that will consume from all queues/consumers'
| def iterconsume(self, limit=None, timeout=None):
| info = {'do_consume': True}
def _error_callback(exc):
if isinstance(exc, socket.timeout):
LOG.debug((_('Timed out waiting for RPC response: %s') % str(exc)))
raise rpc_common.Timeout()
else:
LOG.exception((_('Failed to consume messag... |
'Cancel a consumer thread'
| def cancel_consumer_thread(self):
| if (self.consumer_thread is not None):
self.consumer_thread.kill()
try:
self.consumer_thread.wait()
except greenlet.GreenletExit:
pass
self.consumer_thread = None
|
'Wait for all proxy callback threads to exit.'
| def wait_on_proxy_callbacks(self):
| for proxy_cb in self.proxy_callbacks:
proxy_cb.wait()
|
'Send to a publisher based on the publisher class'
| def publisher_send(self, cls, topic, msg, timeout=None, **kwargs):
| def _error_callback(exc):
log_info = {'topic': topic, 'err_str': str(exc)}
LOG.exception((_("Failed to publish message to topic '%(topic)s': %(err_str)s") % log_info))
def _publish():
publisher = cls(self.conf, self.channel, topic, **kwargs)
publisher.send(ms... |
'Create a \'direct\' queue.
In nova\'s use, this is generally a msg_id queue used for
responses for call/multicall'
| def declare_direct_consumer(self, topic, callback):
| self.declare_consumer(DirectConsumer, topic, callback)
|
'Create a \'topic\' consumer.'
| def declare_topic_consumer(self, topic, callback=None, queue_name=None, exchange_name=None):
| self.declare_consumer(functools.partial(TopicConsumer, name=queue_name, exchange_name=exchange_name), topic, callback)
|
'Create a \'fanout\' consumer'
| def declare_fanout_consumer(self, topic, callback):
| self.declare_consumer(FanoutConsumer, topic, callback)
|
'Send a \'direct\' message'
| def direct_send(self, msg_id, msg):
| self.publisher_send(DirectPublisher, msg_id, msg)
|
'Send a \'topic\' message'
| def topic_send(self, topic, msg, timeout=None):
| self.publisher_send(TopicPublisher, topic, msg, timeout)
|
'Send a \'fanout\' message'
| def fanout_send(self, topic, msg):
| self.publisher_send(FanoutPublisher, topic, msg)
|
'Send a notify message on a topic'
| def notify_send(self, topic, msg, **kwargs):
| self.publisher_send(NotifyPublisher, topic, msg, None, **kwargs)
|
'Consume from all queues/consumers'
| def consume(self, limit=None):
| it = self.iterconsume(limit=limit)
while True:
try:
it.next()
except StopIteration:
return
|
'Consumer from all queues/consumers in a greenthread'
| def consume_in_thread(self):
| def _consumer_thread():
try:
self.consume()
except greenlet.GreenletExit:
return
if (self.consumer_thread is None):
self.consumer_thread = eventlet.spawn(_consumer_thread)
return self.consumer_thread
|
'Create a consumer that calls a method in a proxy object'
| def create_consumer(self, topic, proxy, fanout=False):
| proxy_cb = rpc_amqp.ProxyCallback(self.conf, proxy, rpc_amqp.get_connection_pool(self.conf, Connection))
self.proxy_callbacks.append(proxy_cb)
if fanout:
self.declare_fanout_consumer(topic, proxy_cb)
else:
self.declare_topic_consumer(topic, proxy_cb)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.