a PIKA based, Cuter and more Human rabbitmq queue Utility (´_ゝ`)
Project description
PIKACHU
a PIKA based, Cuter and more Human rabbitmq queue Utility (´_ゝ`)
Quick peek
put a message into queue(independent by namespace):
import PIKACHU
PIKACHU.SimpleProducor("amqp://localhost").put(dict(data="some message"))
get some messages from queue:
for envelope in PIKACHU.SimpleConsumer("amqp://localhost").get():
print("get message:", envelope.message)
envelope.message_read()
use listener to listen message arrival constantly:
def callback(envelope):
print("get message:", envelope.message)
envelope.message_read()
consumer = PIKACHU.SimpleAsyncConsumer(settings.amqp)
ioloop = consumer.start_listen(callback)
ioloop.start()
Installation
pip install git+https://github.com/smilefufu/PIKACHU@master
or from pypi
pip install PI-KA-CHU
Main idea
PIKACHU focus on the business scene of message queue, so users don't have to know the detail concept of rabbitmq, like exchange, exchange type, binding keys... They just have to know what pattern of queue they need to get their bussiness done, and choose it from PIKACHU. That's all.
So PIKACHU plans to provide some common used queue patterns in the human way :) Like the basic pattern put/listen and put/get. Also the publish/subscribe pattern. And other patterns is also in schedule.
PIKACHU.Producer
The base class of all producers. All producers share the same instantiate method with two basic parameters:
- url: The amqp string to connect to rabbitmq
- namespace: Namespace for different business. Non-necessary paramter, default value is "pikachu".
PIKACHU.AsyncConsumer
The base class of all async consumer. Considering nearly all business scene need an async consumer so all consumer in PIKACHU are async consumer, except SimpleConsumer which provides get method. Prameters:
- url: The amqp string to connect to rabbitmq
- namespace: Namespace for different business. Non-necessary paramter, default value is "pikachu".
- tornado_mode: If True, the consumer will use pika.TornadoConnection, which use same ioloop as tornado. Default value is False, a pika.SelectConnection is used, so PIKACHU has it's own ioloop, users have to merge their ioloop with PIKACHU's ioloop if they have one.
PIKACHU.SimpleConsumer
Same parameters as PIKACHU.Producer
Docs
todo: finish the damn doc
Examples
put/get pattern
producor code:
import PIKACHU
producor = PIKACHU.SimpleProducor("amqp://localhost", namespace="my_biz")
message = dict(content="some message")
producor.put(message)
consmer code (gets 10 messages max every time it runs):
import PIKACHU
consumer = PIKACHU.SimpleConsumer("amqp://localhost")
for envelope in consumer.get(max_len=10):
print("get message with content:", envelope.message["conent"])
envelope.message_read() # mark message as read, it's necessary in put/get or put/listen pattern. If you miss it, all unmarked message will be delivered again next time you start your consumer.
put/listen pattern
producor code (same as put/get pattern)
consumer code (wait and listen the messages):
import PIKACHU
def callback(envelope):
print("get message with content:", envelope.message["content"])
envelope.message_read()
consumer = PIKACHU.SimpleAsyncConsumer(settings.amqp)
ioloop = consumer.start_listen(callback)
ioloop.start() # start the loop to keep the process running
publish/subscribe pattern
publisher code:
import PIKACHU
publisher = PIKACHU.BroadCaster("amqp://localhost", namespace="CCTV")
message = dict(news="today's news")
publisher.publish(message, to_hub="ten")
subscriber code:
import PIKACHU
subscriber = PIKACHU.Receiver("amqp://localhost", namespace="CCTV")
def cb(envelope):
print("get news:", envelope.message["news"])
ioloop = subscriber.subscribe(cb, from_hub="ten")
ioloop.start() # start the loop to keep the process running
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file PI-KA-CHU-0.2.5.tar.gz
.
File metadata
- Download URL: PI-KA-CHU-0.2.5.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3840bfec6dd0077eaa99880906fe63e8970c176f3400a69412d6fd0c29178f8e |
|
MD5 | 3e59a11e7ea59642ccdfc9a43fa43372 |
|
BLAKE2b-256 | 77865bef46457a9a1171be35ab37c6bb6e15dab81e18ee3b4c41377212ce42f6 |
File details
Details for the file PI_KA_CHU-0.2.5-py3-none-any.whl
.
File metadata
- Download URL: PI_KA_CHU-0.2.5-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.0 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f7aa0e0415a4a166c53fb2fa9f87694dbf6368df39e0e121416dad8b2a5b6ad |
|
MD5 | 2310396e8240bfefaf223964542657d8 |
|
BLAKE2b-256 | ab6c8fb72eaeab98953f9261c9a2411f5d81af8c06aae843104c7d6dc738a0cf |