Skip to content

Instantly share code, notes, and snippets.

@markmc
Last active Dec 30, 2015
Embed
What would you like to do?
Sample oslo.messaging server with some config options set, but not using config files
import eventlet
eventlet.monkey_patch(os=False)
import logging
from oslo import messaging
logging.basicConfig(level=logging.DEBUG)
class Server(object):
def __init__(self, transport):
self.target = messaging.Target(topic='topic', server='foo')
self._server = messaging.get_rpc_server(transport,
self.target,
[self],
executor='eventlet')
super(Server, self).__init__()
def start(self):
self._server.start()
def wait(self):
self._server.wait()
def ping(self, ctxt):
return 'ping'
conf = get_config_from_dict(dict(rpc_conn_pool_size=100))
transport = messaging.get_transport(conf, 'qpid:///test')
server = Server(transport)
server.start()
server.wait()
import tempfile
from oslo.config import cfg
def get_config_from_dict(values, groups={}):
groups.setdefault('DEFAULT', {}).update(values)
with tempfile.NamedTemporaryFile() as f:
for group, values in groups.iteritems():
f.write('[%s]\n' % group)
for key, value in values.iteritems():
f.write('%s = %s\n' % (key, value))
f.flush()
conf = cfg.ConfigOpts()
conf(args=[], default_config_files=[f.name])
return conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment