Skip to content

Instantly share code, notes, and snippets.

@Gsantomaggio
Created January 25, 2016 09:19
Show Gist options
  • Save Gsantomaggio/76b3fd977d8834653350 to your computer and use it in GitHub Desktop.
Save Gsantomaggio/76b3fd977d8834653350 to your computer and use it in GitHub Desktop.
from amqp import ChannelError, Connection, Message, FrameSyntaxError
import time
import threading
import uuid
def worker(host):
conn = Connection(host=host, userid='test', password='test')
ch = conn.channel()
print "creating exchange - " + host
exchange_name = "ex_" + str(uuid.uuid4())
ch.exchange_declare(exchange_name, 'fanout', auto_delete=True)
queue_name = "queue_" + str(uuid.uuid4())
ch.queue_declare(queue_name, auto_delete=True)
ch.queue_bind(queue_name, exchange_name)
ch.basic_consume(queue=queue_name)
for i in range(900):
msg = Message(
'funtest message',
content_type='text/plain',
application_headers={'foo': i, 'bar': 'baz'},
)
ch.basic_publish(msg, exchange=exchange_name,
routing_key=queue_name)
print "declare 1"
ch.exchange_declare("@@@aaaa", 'fanout', auto_delete=True)
ch.queue_bind(queue_name, "@@@aaaa")
ch.basic_consume(queue=queue_name)
#conn.close
if __name__ == '__main__':
threads = []
time.sleep(1)
for i in range(500):
t = threading.Thread(target=worker, args=["10.100.0.81"])
t2 = threading.Thread(target=worker, args=["10.100.0.82"])
t3 = threading.Thread(target=worker, args=["10.100.0.83"])
threads.append(t)
t.start()
t2.start()
t3.start()
time.sleep(1)
#time.sleep(1)
raw_input("Press Enter to continue...")
print "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment