def __init__(self, options):
Bus.__init__(self)
busaddr = options.rabbitaddr
# Connects to the rabbitmq server
busaddr += "/%2F?connection_attempts=200&heartbeat_interval=" +\
str(options.heartbeat)
self.busaddr = busaddr
params = pika.URLParameters(busaddr)
log.info("Connecting to rabbitmq server at: " + str(busaddr))
b = False
while not b:
try:
self.connection = pika.BlockingConnection(params)
b = True
except pika.exceptions.ConnectionClosed:
log.warning("Cannot connect to rabbitmq at: " + str(busaddr) +
". Retrying..")
time.sleep(0.5)
# TODO: quit here (failed to connect)
self.channel = self.connection.channel()
signal.signal(signal.SIGTERM, self.sigterm_handler)
#: Contains agent instance. This Bus implementation accepts only one
#: agent. Agent must be run using separate RabbitBus() (bus slave)
#: instances.
self.agent = None
self.main_thread_id = thread.get_ident()
# TODO: check if key exists
评论列表
文章目录