예제 #1
0
 def __init__(self,
              channel,
              handlers=None,
              routing_key='#',
              node_id=None,
              app=None,
              queue_prefix='celeryev',
              accept=None,
              queue_ttl=None,
              queue_expires=None):
     self.app = app_or_default(app or self.app)
     self.channel = maybe_channel(channel)
     self.handlers = {} if handlers is None else handlers
     self.routing_key = routing_key
     self.node_id = node_id or uuid()
     self.queue_prefix = queue_prefix
     self.exchange = get_exchange(self.connection
                                  or self.app.connection_for_write())
     self.queue = Queue(
         '.'.join([self.queue_prefix, self.node_id]),
         exchange=self.exchange,
         routing_key=self.routing_key,
         auto_delete=True,
         durable=False,
         queue_arguments=self._get_queue_arguments(
             ttl=queue_ttl,
             expires=queue_expires,
         ),
     )
     self.clock = self.app.clock
     self.adjust_clock = self.clock.adjust
     self.forward_clock = self.clock.forward
     if accept is None:
         accept = {self.app.conf.event_serializer, 'json'}
     self.accept = accept
예제 #2
0
 def __init__(self, channel, handlers=None, routing_key='#',
              node_id=None, app=None, queue_prefix=None,
              accept=None, queue_ttl=None, queue_expires=None):
     self.app = app_or_default(app or self.app)
     self.channel = maybe_channel(channel)
     self.handlers = {} if handlers is None else handlers
     self.routing_key = routing_key
     self.node_id = node_id or uuid()
     self.queue_prefix = queue_prefix or self.app.conf.event_queue_prefix
     self.exchange = get_exchange(
         self.connection or self.app.connection_for_write())
     if queue_ttl is None:
         queue_ttl = self.app.conf.event_queue_ttl
     if queue_expires is None:
         queue_expires = self.app.conf.event_queue_expires
     self.queue = Queue(
         '.'.join([self.queue_prefix, self.node_id]),
         exchange=self.exchange,
         routing_key=self.routing_key,
         auto_delete=True, durable=False,
         message_ttl=queue_ttl,
         expires=queue_expires,
     )
     self.clock = self.app.clock
     self.adjust_clock = self.clock.adjust
     self.forward_clock = self.clock.forward
     if accept is None:
         accept = {self.app.conf.event_serializer, 'json'}
     self.accept = accept
예제 #3
0
 def __init__(self, channel, handlers=None, routing_key='#',
              node_id=None, app=None, queue_prefix=None,
              accept=None, queue_ttl=None, queue_expires=None):
     self.app = app_or_default(app or self.app)
     self.channel = maybe_channel(channel)
     self.handlers = {} if handlers is None else handlers
     self.routing_key = routing_key
     self.node_id = node_id or uuid()
     self.queue_prefix = queue_prefix
     if queue_prefix:
         self.queue_prefix = queue_prefix
     else:
         self.queue_prefix = self.app.conf.CELERY_EVENT_QUEUE_PREFIX
     self.exchange = get_exchange(self.connection or self.app.connection())
     self.queue = Queue(
         '.'.join([self.queue_prefix, self.node_id]),
         exchange=self.exchange,
         routing_key=self.routing_key,
         auto_delete=True, durable=False,
         queue_arguments=self._get_queue_arguments(
             ttl=queue_ttl, expires=queue_expires,
         ),
     )
     self.clock = self.app.clock
     self.adjust_clock = self.clock.adjust
     self.forward_clock = self.clock.forward
     if accept is None:
         accept = {self.app.conf.CELERY_EVENT_SERIALIZER, 'json'}
     self.accept = accept
예제 #4
0
 def __init__(self,
              channel,
              handlers=None,
              routing_key='#',
              node_id=None,
              app=None,
              queue_prefix='celeryev',
              accept=None):
     self.app = app_or_default(app or self.app)
     self.channel = maybe_channel(channel)
     self.handlers = {} if handlers is None else handlers
     self.routing_key = routing_key
     self.node_id = node_id or uuid()
     self.queue_prefix = queue_prefix
     self.exchange = get_exchange(self.connection or self.app.connection())
     self.queue = Queue('.'.join([self.queue_prefix, self.node_id]),
                        exchange=self.exchange,
                        routing_key=self.routing_key,
                        auto_delete=True,
                        durable=False,
                        queue_arguments=self._get_queue_arguments())
     self.clock = self.app.clock
     self.adjust_clock = self.clock.adjust
     self.forward_clock = self.clock.forward
     if accept is None:
         accept = set([self.app.conf.CELERY_EVENT_SERIALIZER, 'json'])
     self.accept = accept
예제 #5
0
 def __init__(self, channel, producer, consumer, no_ack=False):
     self.channel = maybe_channel(channel)
     self.producer = producer
     self.consumer = consumer
     self.no_ack = no_ack
     self.queue = self.consumer.queues[0]
     self.buffer = deque()
     self.consumer.register_callback(self._receive)
예제 #6
0
 def __init__(self, channel, handlers=None, routing_key='#',
              node_id=None, app=None, queue_prefix='celeryev'):
     self.app = app_or_default(app or self.app)
     self.channel = maybe_channel(channel)
     self.handlers = {} if handlers is None else handlers
     self.routing_key = routing_key
     self.node_id = node_id or uuid()
     self.queue_prefix = queue_prefix
     self.exchange = get_exchange(self.connection or self.app.connection())
     self.queue = Queue('.'.join([self.queue_prefix, self.node_id]),
                        exchange=self.exchange,
                        routing_key=self.routing_key,
                        auto_delete=True,
                        durable=False,
                        queue_arguments=self._get_queue_arguments())
     self.adjust_clock = self.app.clock.adjust
예제 #7
0
 def __init__(self, channel, queue, **kwargs):
     self.channel = maybe_channel(channel)
     self.no_ack = kwargs.get("no_ack", False)
     self._queue_declare = kwargs.get("queue_declare", False)
     self.consumer = messaging.Consumer(channel, queue, auto_declare=False)
     self.inqueues = self.consumer.queues
     self.buffer = deque()
     self.consumer.register_callback(self._receive)
     if self._queue_declare:
         for q in self.inqueues:
             try:
                 q.exchange.declare()
             except Exception as e:  # todo fix this exception
                 print e
                 pass
             q.queue_declare()
             q.queue_bind()
     self._last_message = None
     self._lastq = 0
예제 #8
0
    def __init__(self, channel, exchange, **kwargs):
        self._exchange_declare = kwargs.get("exchange_declare", False)
        if isinstance(exchange, Queue):
            self.exchange = exchange.exchange
        elif isinstance(exchange, basestring):
            self.exchange = Exchange(exchange, type="fanout")  # , durable=True)
        else:
            assert isinstance(exchange, Exchange)
            self.exchange = exchange
        self.channel = maybe_channel(channel)
        self.exchange.maybe_bind(self.channel)
        if self._exchange_declare:
            self.exchange.declare()

        self.producer = messaging.Producer(channel, self.exchange,
                                           serializer='json',
                                           routing_key='',
                                           compression=None,
                                           auto_declare=False)
예제 #9
0
    def __init__(self, channel, exchange, **kwargs):
        self._exchange_declare = kwargs.get("exchange_declare", False)
        if isinstance(exchange, Queue):
            self.exchange = exchange.exchange
        elif isinstance(exchange, basestring):
            self.exchange = Exchange(exchange, type="fanout")  # , durable=True)
        else:
            assert isinstance(exchange, Exchange)
            self.exchange = exchange
        self.channel = maybe_channel(channel)
        self.exchange.maybe_bind(self.channel)
        if self._exchange_declare:
            self.exchange.declare()

        self.producer = messaging.Producer(channel, self.exchange,
                                           serializer='json',
                                           routing_key='',
                                           compression=None,
                                           auto_declare=False)
예제 #10
0
 def __init__(self, channel, queue, **kwargs):
     self.channel = maybe_channel(channel)
     self.no_ack = kwargs.get("no_ack", False)
     self._queue_declare = kwargs.get("queue_declare", False)
     self.consumer = messaging.Consumer(channel, queue,
                                        auto_declare=False)
     self.inqueues = self.consumer.queues
     self.buffer = deque()
     self.consumer.register_callback(self._receive)
     if self._queue_declare:
         for q in self.inqueues:
             try:
                 q.exchange.declare()
             except Exception as e:  # todo fix this exception
                 print e
                 pass
             q.queue_declare()
             q.queue_bind()
     self._last_message = None
     self._lastq = 0
예제 #11
0
 def __init__(
     self,
     channel,
     handlers=None,
     routing_key="#",
     node_id=None,
     app=None,
     queue_prefix=None,
     accept=None,
     queue_ttl=None,
     queue_expires=None,
 ):
     self.app = app_or_default(app or self.app)
     self.channel = maybe_channel(channel)
     self.handlers = {} if handlers is None else handlers
     self.routing_key = routing_key
     self.node_id = node_id or uuid()
     self.queue_prefix = queue_prefix or self.app.conf.event_queue_prefix
     self.exchange = get_exchange(
         self.connection or self.app.connection_for_write(),
         name=self.app.conf.event_exchange,
     )
     if queue_ttl is None:
         queue_ttl = self.app.conf.event_queue_ttl
     if queue_expires is None:
         queue_expires = self.app.conf.event_queue_expires
     self.queue = Queue(
         ".".join([self.queue_prefix, self.node_id]),
         exchange=self.exchange,
         routing_key=self.routing_key,
         auto_delete=True,
         durable=False,
         message_ttl=queue_ttl,
         expires=queue_expires,
     )
     self.clock = self.app.clock
     self.adjust_clock = self.clock.adjust
     self.forward_clock = self.clock.forward
     if accept is None:
         accept = {self.app.conf.event_serializer, "json"}
     self.accept = accept