Created
October 16, 2016 21:26
-
-
Save openstacker/2f10c433232dba0a2ea6a804e47ea68f to your computer and use it in GitHub Desktop.
oslo.messaging listener
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/env python | |
# coding: utf-8 | |
from oslo_config import cfg | |
import oslo_messaging | |
import logging | |
import eventlet | |
eventlet.monkey_patch() | |
logging.basicConfig() | |
log = logging.getLogger() | |
log.addHandler(logging.StreamHandler()) | |
log.setLevel(logging.INFO) | |
class NotificationHandler(object): | |
def info(self, ctxt, publisher_id, event_type, payload, metadata): | |
print payload | |
log.info('INFO') | |
def warn(self, ctxt, publisher_id, event_type, payload, metadata): | |
print payload | |
log.info('WARN') | |
def error(self, ctxt, publisher_id, event_type, payload, metadata): | |
print payload | |
log.info('ERROR') | |
log.info('Configuring connection') | |
transport_url = 'rabbit://stackrabbit:passw0rd@127.0.0.1:5672/' | |
transport = oslo_messaging.get_transport(cfg.CONF, transport_url) | |
targets = [oslo_messaging.Target(topic='notifications')] | |
endpoints = [NotificationHandler()] | |
server = oslo_messaging.get_notification_listener(transport, targets, endpoints, allow_requeue=True, executor='eventlet') | |
log.info('Starting up server') | |
server.start() | |
log.info('Waiting for something') | |
server.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment