Created
August 6, 2014 21:36
-
-
Save noelbk/285559e5c1b956b9fba1 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/python | |
from oslo.config import cfg | |
import threading | |
from oslo import messaging | |
import time | |
import datetime | |
import logging | |
log = logging.getLogger(__name__) | |
def timestamp(): | |
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
class OsloTest(): | |
def test(self): | |
url = "rabbit://%(user)s:%(password)s@%(host)s/" % dict( | |
host = '10.35.0.3', | |
password = 'p3uCM_cPfTqasxHlnKnDoyfqtl4uqjXjnunlyzV4e5KGIfC67OwUzaCyyZFp_C8t50m5oCRU', | |
user = 'rabbit-mq-user', | |
) | |
transport = messaging.get_transport(cfg.CONF, url) | |
driver = transport._driver | |
topic = 'y' | |
target = messaging.Target(topic=topic) | |
listener = driver.listen(target) | |
ctxt={"context": True} | |
timeout = 10 | |
def send_main(): | |
log.debug("sending msg") | |
reply = driver.send(target, | |
ctxt, | |
{'send': timestamp()}, | |
wait_for_reply=True, | |
timeout=timeout) | |
log.debug("received reply=%r" % (reply,)) | |
def test(): | |
send_thread = threading.Thread(target=send_main) | |
send_thread.daemon = True | |
send_thread.start() | |
msg = listener.poll() | |
log.debug("received msg=%r" % (msg,)) | |
msg.reply({'reply': timestamp()}) | |
log.debug("sent reply") | |
send_thread.join() | |
# now kill rabbit and try again | |
test() | |
if __name__ == '__main__': | |
FORMAT = '%(asctime)-15s %(process)5d %(thread)5d %(filename)s %(funcName)s %(message)s' | |
logging.basicConfig(level=logging.DEBUG, format=FORMAT) | |
OsloTest().test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment