Skip to main content

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

PI-KA-CHU-0.2.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PI_KA_CHU-0.2.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file PI-KA-CHU-0.2.2.tar.gz.

File metadata

  • Download URL: PI-KA-CHU-0.2.2.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.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for PI-KA-CHU-0.2.2.tar.gz
Algorithm Hash digest
SHA256 1b5d3fe49510e573041e8417211dc0a8226aaeea41c2098e1b2c4fd72c834503
MD5 f80a4b237ad4738ea226e0d1527dd6f6
BLAKE2b-256 a8b9e4d21ee2a36b50934320092fec28582da1f2c5c950f4e3f4c01ed63b842c

See more details on using hashes here.

File details

Details for the file PI_KA_CHU-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: PI_KA_CHU-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 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.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for PI_KA_CHU-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 963a31de699ec6289ea2eb7d9133662deaa57da8d4e1e212afaaabfecd18b44b
MD5 709542ea444af3d90e5b291295e9a27a
BLAKE2b-256 0a27cb7f483b4ddd86376c1886b766a41c61695c50a9366371b0c11f6e0781e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page