Created
April 9, 2013 16:53
-
-
Save wulczer/5347359 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 pika | |
from pika.adapters import TwistedConnection | |
from twisted.internet import task | |
def ok(ret): | |
print "published" | |
return ret | |
def ko(f): | |
print "FAILED", f | |
def publish(channel): | |
d = channel.basic_publish('exchange', '1', 'foo') | |
return d.addCallback(ok).addErrback(ko) | |
def start_publishing(channel): | |
print "channel open" | |
lc = task.LoopingCall(publish, channel) | |
lc.start(1) | |
def start(conn): | |
print "connected" | |
return conn.channel().addCallback(start_publishing) | |
params = pika.ConnectionParameters() | |
conn = TwistedConnection(params, start) | |
conn.ioloop.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment