Пример #1
0
def sync_if_local_memory(func, *args, **kwargs):
    """
    Runs locally, synchronous if connection is memory://
    This will create in-memory transport if messaging is
    not configured.

    This allows to run synchronous queue in deployments
    which don't have external broker deployed
    """

    try:
        return func(*args, **kwargs)
    finally:
        if getattr(connection.connection, 'driver_name', None) == 'memory':
            # hack explained:
            # when using memory://, first run usually contains only message for
            # specific queue. Subsequent runs will deliver the same message
            # in topic queue and broadcast one, which is weird.
            # that's why for first run we stop after first message, and then after
            # two (so we catch topic and broadcast)
            # This may change in the future
            global LOCAL_STARTED
            max_messages = 1 if not LOCAL_STARTED else 2
            LOCAL_STARTED = True
            worker = Consumer(connection, max_messages)
            worker.run()
Пример #2
0
 def handle(self, **options):
     with connection:
         try:
             logger.info("Consumer starting.")
             worker = Consumer(connection)
             worker.run()
         except KeyboardInterrupt:
             logger.info("Consumer stopped.")
Пример #3
0
    def handle(self, **options):
        from kombu import BrokerConnection
        from geonode.messaging.consumer import Consumer

        with BrokerConnection(settings.BROKER_URL) as connection:
            try:
                logger.info("Consumer starting.")
                worker = Consumer(connection)
                worker.run()
            except KeyboardInterrupt:
                logger.info("Consumer stopped.")
Пример #4
0
    def handle(self, **options):
        from kombu import BrokerConnection
        from geonode.messaging.consumer import Consumer

        with BrokerConnection(BROKER_URL) as connection:
            try:
                logger.info("Consumer starting.")
                worker = Consumer(connection)
                worker.run()
            except KeyboardInterrupt:
                logger.info("Consumer stopped.")
Пример #5
0
 def test_consumer(self):
     with connection:
         try:
             worker = Consumer(connection)
             self.assertTrue(worker is not None)
         except:
             self.fail("could not create a Consumer.")