예제 #1
0
파일: messages.py 프로젝트: ziqizh/h
def process_messages(settings, routing_key, work_queue, raise_error=True):
    """
    Configure, start, and monitor a realtime consumer for the specified
    routing key.

    This sets up a :py:class:`h.realtime.Consumer` to route messages from
    `routing_key` to the passed `work_queue`, and starts it. The consumer
    should never return. If it does, this function will raise an exception.
    """
    def _handler(payload):
        try:
            message = Message(topic=routing_key, payload=payload)
            work_queue.put(message, timeout=0.1)
        except Full:
            log.warn('Streamer work queue full! Unable to queue message from '
                     'h.realtime having waited 0.1s: giving up.')

    conn = realtime.get_connection(settings)
    sentry_client = h.sentry.get_client(settings)
    statsd_client = h.stats.get_client(settings)
    consumer = Consumer(connection=conn,
                        routing_key=routing_key,
                        handler=_handler,
                        sentry_client=sentry_client,
                        statsd_client=statsd_client)
    consumer.run()

    if raise_error:
        raise RuntimeError('Realtime consumer quit unexpectedly!')
예제 #2
0
파일: messages.py 프로젝트: bZichett/h
def process_messages(settings, routing_key, work_queue, raise_error=True):
    """
    Configure, start, and monitor a realtime consumer for the specified
    routing key.

    This sets up a :py:class:`h.realtime.Consumer` to route messages from
    `routing_key` to the passed `work_queue`, and starts it. The consumer
    should never return. If it does, this function will raise an exception.
    """

    def _handler(payload):
        try:
            message = Message(topic=routing_key, payload=payload)
            work_queue.put(message, timeout=0.1)
        except Full:
            log.warn('Streamer work queue full! Unable to queue message from '
                     'h.realtime having waited 0.1s: giving up.')

    conn = realtime.get_connection(settings)
    sentry_client = h.sentry.get_client(settings)
    consumer = Consumer(connection=conn,
                        routing_key=routing_key,
                        handler=_handler, sentry_client=sentry_client)
    consumer.run()

    if raise_error:
        raise RuntimeError('Realtime consumer quit unexpectedly!')