Skip to content

Instantly share code, notes, and snippets.

@grasses
Last active July 11, 2017 08:02
Show Gist options
  • Save grasses/7b37351b735c4439daa68c7e3a87d4a8 to your computer and use it in GitHub Desktop.
Save grasses/7b37351b735c4439daa68c7e3a87d4a8 to your computer and use it in GitHub Desktop.
rabbitmq
#!/usr/bin/env python2.7.13
import pika, threading, random
scope = []
hostname = "10.1.20.222"
def gen(size):
char_set = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()"
pw = ""
for i in range(size):
next_index = random.randrange(len(char_set))
pw = pw + char_set[next_index]
return pw
class Product(threading.Thread):
def __init__(self, cid):
self.cid = cid
self.scope = gen(16)
scope.append(self.scope)
threading.Thread.__init__(self)
parameters = pika.ConnectionParameters(host=hostname, port=5672, virtual_host='/', credentials=pika.PlainCredentials('seclab', 'seclab605607!'))
self.connection = pika.BlockingConnection(parameters)
self.channel = self.connection.channel()
self.channel.queue_declare(queue=self.scope)
def run(self):
for c in range(100000):
if c % 5000 == 0:
print("=> {:d}:{:d}".format(self.cid, c))
self.channel.basic_publish(exchange='', routing_key=self.scope, body=str(c) + '-' + gen(32))
self.connection.close()
if __name__ == '__main__':
print("=> please input host hostname:\n")
hostname = raw_input()
pooling = []
for i in range(10):
tmp = Product(i)
tmp.start()
pooling.append(tmp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment