Skip to main content

A small, in-process message bus implementation.

Project description

mbuslite provides a message bus implementation embedded within the application’s process.

With it, you can loosely couple your application components. It implements the publish-subscribe pattern.

Motivation

Having worked with crossbar and autobahn, as well as DBus, I like the message bus pattern. I’ve wanted to use it in some projects to achieve the same loose coupling between internal components.

Having also worked wih sqlite, I like the simplicity of a library instead of a remote service.

Thus, mbuslite.

Installation

pip install mbuslite

Usage

To get started, import mbuslite.Bus and start calling .subscribe() and .publish().

from mbuslite import Bus

class Producer:
    def announce( self ):
        Bus.publish( 'topic.name', 'Hello, consumers!' )

class Consumer:
    def __init__( self ):
        Bus.subscribe( 'topic.name', self.on_message )
    def on_message( self, msg ):
        print( msg )

consumer1 = Consumer()
consumer2 = Consumer()
consumer3 = Consumer()
producer = Producer()
producer.announce()
Hello, consumers!
Hello, consumers!
Hello, consumers!

Publishers and subscribers must agree upon a call signature as the arguments are passed as-is by mbuslite.

def handler( one, two, three, four ):
    pass
Bus.subscribe( 'foo', handler )
Bus.publish( 'foo', 1, 2, three = 3, four = 4 )

See more in examples/.

Logging

mbuslite makes use of the python logging module. To manipulate mbuslite’s logging behavior, use logging.getLogger('mbuslite') or import mbuslite and manipulate mbuslite.logger. For example, you can set that logger’s level to info or debug to get additional information about what mbuslite is doing.

Note that mbuslite does not configure the logging module, so unless your application does, logs from mbuslite will not be written anywhere, even those that match the default level of WARNING. You are encouraged to at least call logging.basicConfig() to ensure you see warning messages from mbuslite. For example, unhandled exceptions from handlers you subscribe to topics are logged as warnings and will not be available if you never configure logging.

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

mbuslite-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

mbuslite-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file mbuslite-0.1.0.tar.gz.

File metadata

  • Download URL: mbuslite-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

File hashes

Hashes for mbuslite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 22321dac3386a830b66c3cb3f8c6854f37938376e8bb5812c9556ab56015e0e9
MD5 1481b51c8591ddf795c9ca90492ba4a3
BLAKE2b-256 690a73e0458565a8de30e9b00532178af430d68ec9b24a93c098ff27ff4f02ef

See more details on using hashes here.

File details

Details for the file mbuslite-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mbuslite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.6

File hashes

Hashes for mbuslite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f04de1019113e35201f7f146811e1309c41805773189ebfda1e129757dcb12a2
MD5 2177134275f81c25745907cf61b9d90a
BLAKE2b-256 224157bcf0bddb79bc129b5de3938d567a867639a3f1155d889372c5a27d6bc4

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