class BlockingQueuePublisher(object): """ Class that is responsible for sending messages to the amqp exchange. """ implements(IQueuePublisher) def __init__(self): self.reconnect() def reconnect(self): connectionInfo = getUtility(IAMQPConnectionInfo) queueSchema = getUtility(IQueueSchema) self._client = BlockingPublisher(connectionInfo, queueSchema) def publish(self, exchange, routing_key, message, createQueues=None, mandatory=False, immediate=False, headers=None, declareExchange=True): if createQueues: for queue in createQueues: self._client.createQueue(queue) self._client.publish(exchange, routing_key, message, mandatory=mandatory, immediate=immediate, headers=headers, declareExchange=declareExchange) @property def channel(self): return self._client.getChannel() def close(self): """ Closes the channel and connection """ self._client.close()
class BlockingQueuePublisher(object): """ Class that is responsible for sending messages to the amqp exchange. """ implements(IQueuePublisher) def __init__(self): self.reconnect() def reconnect(self): connectionInfo = getUtility(IAMQPConnectionInfo) queueSchema = getUtility(IQueueSchema) self._client = BlockingPublisher(connectionInfo, queueSchema) def publish(self, exchange, routing_key, message, createQueues=None, mandatory=False, headers=None, declareExchange=True): if createQueues: for queue in createQueues: if not self._client.queueExists(queue): self.reconnect() self._client.createQueue(queue) self._client.publish(exchange, routing_key, message, mandatory=mandatory, headers=headers, declareExchange=declareExchange) @property def channel(self): return self._client.getChannel() def close(self): """ Closes the channel and connection """ self._client.close()