Browse files

Added fake-bus script.

  • Loading branch information...
1 parent 2c0773b commit de74356ff039f73978dd1d0aa314a5b3e281af5f @ralphbean committed Mar 21, 2012
Showing with 45 additions and 0 deletions.
  1. +45 −0 tools/fake-bus.py
View
45 tools/fake-bus.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+import random
+import time
+import zmq
+import simplejson
+
+# TODO -- have this use fedmsg.
+
+def main():
+ """ main method """
+
+ # Prepare our context and publisher
+ context = zmq.Context(1)
+ publisher = context.socket(zmq.PUB)
+ publisher.bind("tcp://*:6543")
+ time.sleep(1)
+
+ # Probabilities of us emitting an event on each topic.
+ probs = {
+ 'koji': 0.35,
+ 'bodhi': 0.2,
+ 'pkgdb': 0.1,
+ 'fas': 0.2,
+ 'autoqa': 0.3,
+ 'tagger': 0.6,
+ }
+
+ i = 0
+ while True:
+ for topic, thresh in probs.iteritems():
+ if random.random() < thresh:
+ publisher.send_multipart(
+ [topic, simplejson.dumps({
+ 'topic': topic, 'msg': "We" + str(i)
+ })]
+ )
+ time.sleep(random.random())
+ i = i + 1
+
+ # We never get here but clean up anyhow
+ publisher.close()
+ context.term()
+
+if __name__ == "__main__":
+ main()

0 comments on commit de74356

Please sign in to comment.