def run_producer():
    connection = connect()
    channel = open_channel(connection)

    use_topic_exchange(channel)
    bind_queue(channel,
               'europe_queue',
               routing_pattern='europe.*',
               exchange_name='topic_exchange')
    bind_queue(channel,
               'asia_queue',
               routing_pattern='asia.*',
               exchange_name='topic_exchange')
    bind_queue(channel,
               'americas_queue',
               routing_pattern='americas.*',
               exchange_name='topic_exchange')

    keys = ("europe.cr", "europe.sr", "europe.pl", "asia.china",
            "americas.canada", "americas.chile")
    for key in keys:
        print(key)
        channel.basic_publish(exchange='topic_exchange',
                              routing_key=key,
                              body='Hello World! #{k}'.format(k=key))

    print('Sent \'Hello World!\' to all selected regions')
    connection.close()
Beispiel #2
0
def run_consumer(queue_name):
    connection = connect()
    channel = open_channel(connection, queue_name)
    channel.basic_qos(prefetch_count=1)
    channel.basic_consume(on_receive, queue=queue_name, no_ack=False)
    print('Waiting for messages in queue "{q}". To exit press CTRL+C'.format(
        q=queue_name))
    print("...")
    channel.start_consuming()
def run_producer(queue_name):
    connection = connect()
    channel = open_channel(connection)

    for i in range(1, 11):
        channel.basic_publish(exchange='',
                              routing_key=queue_name,
                              body='Hello World! #{i}'.format(i=i))

    print('Sent \'Hello World!\' ten times into the queue "{q}"'.format(q=queue_name))
    connection.close()
Beispiel #4
0
def run_producer(queue_name):
    connection = connect()
    channel = open_channel(connection, queue_name)

    channel.basic_publish(exchange='',
                          routing_key=queue_name,
                          body='Hello World!')

    print('Sent \'Hello World!\' message into the queue "{q}"'.format(
        q=queue_name))

    connection.close()
def run_producer():
    connection = connect()
    channel = open_channel(connection,
                           queue_name='priority_queue_3',
                           max_priority=100)

    for i in range(0, 100):
        priority = 100 - i
        prop = BasicProperties(priority=priority)
        channel.basic_publish(
            exchange='',
            routing_key='priority_queue_3',
            body='Hello World! #{i} msg with priority {p}'.format(i=i,
                                                                  p=priority),
            properties=prop)

    connection.close()
def run_producer():
    connection = connect()
    channel = open_channel(connection)

    use_fanout(channel)
    bind_queue(channel, 'fronta1')
    bind_queue(channel, 'fronta2')
    bind_queue(channel, 'fronta3')

    channel.basic_publish(exchange='fanout_exchange',
                          routing_key='',
                          body='Hello World!')

    print(
        'Sent \'Hello World!\' message into three queues "fronta1", "fronta2", and "fronta3"'
    )

    connection.close()
Beispiel #7
0
def run_producer():
    connection = connect()
    channel = open_channel(connection)

    use_fanout(channel)
    bind_queue(channel, 'fronta1')
    bind_queue(channel, 'fronta2')
    bind_queue(channel, 'fronta3')

    for i in range(1, 11):
        channel.basic_publish(exchange='fanout_exchange',
                              routing_key='',
                              body='Hello World! #{i}'.format(i=i))

    print(
        'Sent \'Hello World!\' ten times into three queues "fronta1", "fronta2", and "fronta3"'
    )
    connection.close()
#!/usr/bin/env python
from rabbitmq_connect import connect, open_channel

connection = connect()
channel = open_channel(connection)

for i in range(1, 11):
    channel.basic_publish(exchange='',
                          routing_key='test',
                          body='Hello World! #{i}'.format(i=i))

print("Sent 'Hello World!' ten times")
connection.close()