def producer_pool(self): if self._producer_pool is None: self._producer_pool = ProducerPool( self.app.pool, limit=self.app.pool.limit, Producer=self.Producer, ) return self._producer_pool
class Producer(ConnectibleMixin): """Produce and publish messages""" def __init__(self, exchange, route=None): self.producers = ProducerPool(self.connections) self.exchange = exchange self.route = route or '' super(Producer, self).__init__() def publish(self, body, route=None): """Publish message. :param body: Message body. :param route: Message route. :type route: str or None """ with self.producers.acquire(block=True) as producer: producer.publish(msgpack.packb(body, use_bin_type=True), exchange=self.exchange, routing_key=route or self.route)
def producer_pool(self): return ProducerPool(self.app.pool, limit=self.app.pool.limit, Producer=self.TaskProducer)
def __init__(self, exchange, route=None): self.producers = ProducerPool(self.connections) self.exchange = exchange self.route = route or '' super(Producer, self).__init__()