Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __setup_rackhd_style_amqp(self):
"""
Need to make exchanges and named queus to make this
look like a RackHD instance amqp.
"""
con = Connection(hostname=self.host, port=self.ssl_port, ssl=False)
on_task = self.__assure_exchange(con, 'on.task', 'topic')
self.__assure_named_queue(con, on_task, 'ipmi.command.sel.result')
self.__assure_named_queue(con, on_task, 'ipmi.command.sdr.result')
self.__assure_named_queue(con, on_task, 'ipmi.command.chassis.result')
on_events = self.__assure_exchange(con, 'on.events', 'topic')
self.__assure_named_queue(con, on_events, 'graph.finished')
self.__assure_named_queue(con, on_events, 'polleralert.sel.updated', '#')
self.__assure_exchange(con, 'on.heartbeat', 'topic')
def wait_for_amqp(hostname, port, userid, password, ssl=False, timeout=60,
extra_check_fn=None):
# Delay import to facilitate module use in limited virtualenvs.
import kombu
c = kombu.Connection(hostname=hostname, port=port, userid=userid,
password=password, ssl=ssl)
start = time.time()
while True:
try:
c.connection
return
except Exception:
pass
if extra_check_fn:
extra_check_fn()
if time.time() - start > timeout:
raise Exception('Timeout reached waiting for AMQP')
def setup(self):
self.connection = Connection('pyamqp://')
self.transport = self.connection.transport
def run(self):
logger.info("Running AMQP consumer")
with Connection(self._bus_url) as connection:
self.connection = connection
super().run()
def __init__(self, exchange_name, broker_url, mode=ASYNC):
"""初始化生产者
Args:
exchange_name (string): 路由名称
broker_url (string): 连接地址
mode (int): 发送
"""
self.exchange_name = exchange_name
self.broker_url = broker_url
self.mode = mode
self.exchange = Exchange(exchange_name, type='direct')
self.connection = Connection(broker_url)
start_commissaire_service, 'commissaire-watcher-service',
context, [
'commissaire-watcher-service',
'--config-file',
'../commissaire-service/conf/watcher.conf'])
if context.config.userdata.get('start-commissaire-server'):
context.PROCESSES['commissaire-server'] = try_start(
start_commissaire_server, 'commissaire-server',
context, [
'--authentication-plugin',
'commissaire_http.authentication.httpbasicauth:'
'filepath=../commissaire-http/conf/users.json'])
# Set up a Kombu queue to receive notifications.
context.BUS_CONNECTION = kombu.Connection(context.BUS_URI)
channel = context.BUS_CONNECTION.default_channel
exchange = kombu.Exchange(
name='commissaire',
type='topic',
channel=channel)
context.NOTIFY_QUEUE = kombu.Queue(
name='behave-tests',
exchange=exchange,
routing_key='notify.storage.*.*',
channel=channel)
context.NOTIFY_QUEUE.declare()
def __init__(self, uri=None, queue='logging', level=NOTSET,
filter=None, bubble=False):
Handler.__init__(self, level, filter, bubble)
try:
import kombu
except ImportError:
raise RuntimeError('The kombu library is required for '
'the RabbitMQSubscriber.')
if uri:
connection = kombu.Connection(uri)
self.queue = connection.SimpleQueue(queue)
def connect(self):
if not self.connection:
self.connection = Connection(
hostname=self.settings.host,
port=self.settings.port,
userid=self.settings.user,
password=self.settings.password,
virtual_host=self.settings.vhost,
ssl=self.settings.ssl
)
def main():
#connect and declare the queues
connString='amqp://guest:guest@{0}:5672//'.format(options.mqserver)
mqConn=Connection(connString)
eventTaskQueue=Queue(options.taskqueue)
eventTaskQueue(mqConn).declare()
kConsumer(mqConn,eventTaskQueue,es).run()
def __init__(self, name, url="amqp://", maxsize=0, lazy_limit=True):
"""
Constructor for KombuQueue
url: http://kombu.readthedocs.org/en/latest/userguide/connections.html#urls
maxsize: an integer that sets the upperbound limit on the number of
items that can be placed in the queue.
"""
self.name = name
self.conn = Connection(url)
self.queue = self.conn.SimpleQueue(self.name, no_ack=True, serializer='umsgpack')
self.maxsize = maxsize
self.lazy_limit = lazy_limit
if self.lazy_limit and self.maxsize:
self.qsize_diff_limit = int(self.maxsize * 0.1)
else:
self.qsize_diff_limit = 0
self.qsize_diff = 0