Skip to main content

A simple application layer event-bus lib, support redis/mqtt/rabbitmq.

Project description

pbus

A simple application layer event-bus lib, support redis/mqtt/rabbitmq.

Install

 pip install pbus

Useage

  1. Use with Redis/MQTT/RabbitMQ Bus class.

Subscriber

import pbus
bus = pbus.RedisBus(host='127.0.0.1')   # need "pip install redis"
# or
bus = pbus.MQTTBus(host='127.0.0.1')   # need "pip install paho-mqtt"
# or
bus = pbus.RabbitMQBus(host='127.0.0.1')   # need "pip install pika"
ps = bus.subscriber('test')
for data in ps.listen():
    print(data)

Publish

import pbus
bus = pbus.RedisBus(host='127.0.0.1')
# or
bus = pbus.MQTTBus(host='127.0.0.1')
# or
bus = pbus.RabbitMQBus(host='127.0.0.1')
bus.publish('test', 'Hello')
  1. Use with URI(recommend)
import pbus
bus = pbus.connect("redis://:password@127.0.0.1:6379/2")    # with db 2
# or
bus = pbus.connect("mqtt://username:password@127.0.0.1:1883")    #
# or 
bus = pbus.connect("amqp://username:password@127.0.0.1:5672/myexchange")    #  with "myexchange" exchange

# ...... other code
  1. Test event-bus speed.
  • a. Run consumer client
python -m pbus -u redis://127.0.0.1
  • b. Run producer client
python -m pbus -u redis://127.0.0.1 -p

You will see:

connecting to bus redis://127.0.0.1 ...
connecte success!
subscribing to pbus ...
subscribe success!
waiting data from pbus
1 :  count 27748 time: 5000ms speed: 5549/s total 27748
2 :  count 83135 time: 5000ms speed: 16627/s total 110883
3 :  count 86416 time: 5000ms speed: 17283/s total 197299
4 :  count 72546 time: 5000ms speed: 14509/s total 269845

Ctrl+C to stop test.

Click to view more information!

CHANGES

1.0.0

  • First version

1.1.0

  • Support MQTT and RabbitMQ
  • Support connect with URI

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

pbus-1.1.0.tar.gz (9.9 kB view details)

Uploaded Source

File details

Details for the file pbus-1.1.0.tar.gz.

File metadata

  • Download URL: pbus-1.1.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.6.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.10

File hashes

Hashes for pbus-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0dee602b1eeb34d636458aeff317e9762f8c3b9edc487e50cc30145edb42d7da
MD5 7aa561b32ace918c3258c83c4ee5af5f
BLAKE2b-256 e2978bf3ef7f51b94fe4e195d7a68439c2704ea722f36ef4e4b57734bf5a90c8

See more details on using hashes here.

Supported by

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