Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Created September 22, 2012 16:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ralphbean/3766683 to your computer and use it in GitHub Desktop.
Files needed for
mkvirtualenv my_virtualenv
git clone git://github.com/ralphbean/fedmsg.git
cd fedmsg
python setup.py develop
cd ..
mkdir my_consumer_project
cd my_consumer_project
# First copy my_consumer.py and setup.py from this gist into this directory.
# Then copy the development fedmsg config from the other git clone like this
cp -rf ../fedmsg/fedmsg.d/ .
# Finally, copy the my_consumer_config.py into this ./fedmsg.d/ directory.
# Setup your consumer by running
python setup.py develop
# Start the fedmsg-hub (which should pick up your consumer) with:
fedmsg-hub
# Go and make an edit to your account at https://admin.stg.fedoraproject.org/accounts
# You should see the dict-message get printed out.
""" Just an example consumer to show how to write a service that does stuff in
response to message on the `fedmsg bus <http://fedmsg.rtfd.org>`_.
Author: Ralph Bean
"""
import fedmsg.consumers
class MyTestConsumer(fedmsg.consumers.FedmsgConsumer):
# my_consumer_enabled must be set to True in the config in fedmsg.d/ for
# this consumer to be picked up and run when the fedmsg-hub starts.
config_key = "my_consumer_enabled"
# I'm only interested in messages from FAS
topic = "org.fedoraproject.stg.fas*"
def consume(self, message):
import pprint
print "Hello there.. I got a message from FAS. Its a python dict."
pprint.pprint(message)
""" This is a config file that must appear in ./fedmsg.d/ alongside the other config files from the fedmsg development checkout.
In production, this should go into /etc/fedmsg.d/ but for development it can just live in your cwd/pwd.
"""
config = {
'my_consumer_enabled': True,
}
""" A setuptool installer that crucially declares the consumer on an entry-point
that moksha is looking for.
Without this, fedmsg-hub won't find your consumer.
"""
from setuptools import setup
setup(
name='my_consumer_project',
entry_points="""
[moksha.consumer]
hello = my_consumer:MyTestConsumer
""",
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment