Created
February 13, 2015 13:59
-
-
Save dbrandt/76acf17454914016588b to your computer and use it in GitHub Desktop.
RabbitMQ ping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rabbitpy | |
def send(): | |
with rabbitpy.Connection() as conn: | |
with conn.channel() as chan: | |
ex = rabbitpy.DirectExchange(chan, "ping_ex") | |
ex.declare() | |
while True: | |
m = rabbitpy.Message(chan, "ping") | |
m.publish(ex, "ping_ex") | |
yield | |
def collect(): | |
with rabbitpy.Connection() as conn: | |
with conn.channel() as chan: | |
ex = rabbitpy.DirectExchange(chan, "ping_ex") | |
ex.declare() | |
q = rabbitpy.Queue(chan) | |
q.declare() | |
q.bind(ex, "ping_ex") | |
for m in q: | |
m.ack() | |
yield m.body | |
if __name__ == "__main__": | |
import sys | |
import time | |
if len(sys.argv) == 2 and sys.argv[1] == "send": | |
for x in send(): | |
time.sleep(1) | |
else: | |
for x in collect(): | |
print(x.decode("utf8")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment