Skip to main content

Publish/Subscribe pattern build with RabbitMQ and Protocol Buffers

Project description

Publish/Subscribe pattern build with RabbitMQ and Protocol Buffers.

Installation

To install miPubSub, use pipenv (or pip):

$ pipenv install -e git@github.com:azylinski/miPubSub.git@master#egg=miPubSub

Run RabbitMQ

In order to use miPubSub, you need to have access to RabbitMQ server. To setup locally with docker:

docker run -d \
  --name demo-rabbit \
  -p 5672:5672 \
  -p 15672:15672 \
  rabbitmq:3.6.15-management-alpine

Define events structure

# schemas/events/user.proto

syntax = "proto3";

package events;


message User {
  string name = 1;
  string email = 2;
}
# compile proto files
protoc -I=schemas/events/ --python_out=proto/ schemas/events/*.proto

Example

# producer.py

from miPubSub import PubSub
from proto.user_pb2 import User


ps = PubSub('user_management')

u = User(name='Adam West', email='adam.west@mail.com')

ps.publish('signup_completed', u)
# consumer.py

from miPubSub import PubSub
from proto.user_pb2 import User


ps = PubSub('mailer')

@ps.listen('signup_completed', User)
def on_signup_completed(user):
    # Send welcome email to: user.email
    pass

ps.run()

How it works

TBD

More details on rabbitmq pub/sub: https://www.rabbitmq.com/tutorials/tutorial-three-python.html

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
miPubSub-0.1.dev1-py2.py3-none-any.whl (5.7 kB) Copy SHA256 hash SHA256 Wheel py2.py3

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page