Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gdoermann/classymq
RabbitMQ class based python library.
https://github.com/gdoermann/classymq
Last synced: about 2 months ago
JSON representation
RabbitMQ class based python library.
- Host: GitHub
- URL: https://github.com/gdoermann/classymq
- Owner: gdoermann
- License: bsd-3-clause
- Created: 2014-10-02T05:22:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-03T21:47:59.000Z (about 10 years ago)
- Last Synced: 2024-10-11T00:22:07.062Z (3 months ago)
- Language: Python
- Size: 199 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
classymq
===============classymq is a class based RabbitMQ library.
[Documentation](https://classymq.readthedocs.org/en/latest/)
[Report a Bug](https://github.com/gdoermann/classymq/issues)
[Users Mailing List](https://groups.google.com/forum/?fromgroups#!forum/classymq)
[Dev Mailing List](https://groups.google.com/forum/?fromgroups#!forum/classymq-dev)
## Installation
```
pip install classymq
```## Getting Started
```python
#first, define an exchange
from classymq import exchanges
class MyExchange(exchanges.BaseExchange):
KEY = "myexchange"
TYPE = exchanges.EXCHANGE_TYPES.TOPIC
NOWAIT = True
DURABLE = False
#second, setup the queue
from classymq import queues
class MyQueue(queues.BaseQueue):
KEY = "myqueue"
NOWAIT = True
DURABLE = False#third, create JSON serializable message definition class
class MyMessage(AttrDict):
def __init__(self, message, uuid=None):
AttrDict.__init__(self)
self.message = message
self.uuid = uuid#fourth, create a consumer and register it to do something on incoming messages
from classymq import consumers
class MyConsumer(consumers.JsonMessageConsumer):
EXCHANGE = MyExchange
QUEUE = MyQueue
ROUTING_KEY = '#'
MESSAGE_CLASS = MyMessage
def __init__(self, key_params=None, rate=None, routing_keys=None):
super(MyConsumer, self).__init__(key_params, rate, routing_keys)
self.processor.register(self.do_something)
def do_something(self, message):
print 'recieved message {}: {}'.format(message.uuid, message.message)#fifth, create a producer class
from classymq import producers, synchronous# twisted producer
class MyProducer(producers.JsonProducer):
CONSUMER = MyConsumer# synchronous producer (pika)
class MySynchronousProducer(synchronous.JsonProducer):
CONSUMER = MyConsumer#next, start listening on the consumer side
# myservice.py
from twisted.internet.defer import inlineCallbacks
from twisted.internet import reactor
from classymq import factory
import MyConsumerconsumer = MyConsumer()
@inlineCallbacks
def run():
factory = AmqpFactory()
yield factory.connect()
factory.read(consumer)run()
reactor.run()#finally, produce a message
>>> import MySynchronousProducer, MyMessage, uuid
>>> producer = MySynchronousProducer()
>>> message = MyMessage("Hello world!", str(uuid.uuid1())
>>> producer.push(message)