Exemplo n.º 1
0
def main():
    connection = kombu.BrokerConnection(**config.get_rabbitmq_config())
    channel = connection.channel()
    twitter_exchange = kombu.Exchange("twitter", type="topic")
    producer = kombu.Producer(channel, twitter_exchange)
    control_queue = connection.SimpleBuffer("twitter_pump")
    try:
        twitter = twython.Twython(**config.get_twitter_config())
        handle_tweets(twitter, producer, control_queue)
    finally:
        channel.close()
        connection.close()
Exemplo n.º 2
0
def main(options):
    connection = kombu.BrokerConnection(**config.get_rabbitmq_config())
    channel = connection.channel()
    # By default messages sent to exchanges are persistent (delivery_mode=2),
    # and queues and exchanges are durable.
    try:
        twitter_exchange = kombu.Exchange("twitter", type="topic")
        queue = kombu.Queue(name=str(random.random()),
                            exchange=twitter_exchange,
                            routing_key=options.pattern, durable=False,
                            auto_delete=True)
        consumer = kombu.Consumer(channel, queue, callbacks=[handle_tweets])
        consumer.consume()
        while True:
            connection.drain_events()
    finally:
        channel.close()
        connection.close()
Exemplo n.º 3
0
def main(options):
    list_of_ints_re = re.compile("^\s*(\d+)(\s*,+\s*\d+)*\s*$")
    delimiter_re = re.compile("\s*,\s*")
    connection = kombu.BrokerConnection(**config.get_rabbitmq_config())
    channel = connection.channel()
    control_queue = connection.SimpleBuffer(options.queue)
    try:
        while True:
            cmd = raw_input(options.prompt)
            cmd = cmd.strip()
            if list_of_ints_re.match(cmd):
                cmd = simplejson.dumps(
                    [int(i) for i in delimiter_re.split(cmd) if i])
            if options.encrypt:
                cmd = cmd.encode("rot13")
            control_queue.put(
                cmd, delivery_mode=kombu.entity.TRANSIENT_DELIVERY_MODE)
            do_quit = ((cmd == "quit" and not options.encrypt) or
                       (options.encrypt and cmd.decode("rot13") == "quit"))
            if do_quit:
                break
    finally:
        channel.close()
        connection.close()