Coder Social home page Coder Social logo

anypubsub's Introduction

anypubsub

https://travis-ci.org/smarzola/anypubsub.png?branch=master https://coveralls.io/repos/github/smarzola/anypubsub/badge.svg?branch=master

A generic interface wrapping multiple backends to provide a consistent pubsub API.

Usage

Create a pubsub object:

from anypubsub import create_pubsub
pubsub = create_pubsub('memory')

or create a pubsub object from settings:

from anypubsub import create_pubsub_from_settings
pubsub = create_pubsub_from_settings({'anypubsub.backend': 'memory'}, prefix='anypubsub.')

Subscribe to a channel:

subscriber = pubsub.subscribe('a_channel')

you can also subscribe to multiple channels:

subscriber = pubsub.subscribe('a_channel', 'b_channel')

the subscriber is an iterator object that returns the next published message at each loop increment, and blocks until next message is published.

Publish a message to a channel:

pubsub.publish('a_channel', 'hello world!')

message = next(subscriber)
assert message == 'hello world!'

Supported backends

  • memory
  • redis
  • mongodb
  • amqp (tested with rabbitmq)

Backend specific optional settings

redis:

host: hostname or full redis url, default: localhost
port: default 6379
db: default 0
max_connections: connection pool max connections
connection_pool: an already created redis-py ConnectionPool

mongodb:

host: hostname or full mongodb url
port: mongodb port
max-pool-size: connection pool max connections
client: an already created pymongo MongoClient
database: database used to store messages, default anypubsub
collection: collection used to store messages, default anyps_messages
collection_size: messages collection size in bytes, default 10MB

anypubsub's People

Contributors

smarzola avatar edouardpoitras avatar noamkush avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.