PUB-SUB using ZeroMQ, used Redis to persist tasks/messages.
- Redis
- Python 3
$ cd <project-dir>
$ export PYTHONPATH="$PYTHONPATH:." # . corresponds to current directory(project-dir).
$ virtualenv -p python3 .env # Create virtual environment.
$ pip install -r requirements.txt # Install dependencies.
And then publisher can be started as -
$ python publisher.py
and subscriber(s) can be started as -
$ python subscriber.py
- Traditional Publisher-Subscriber model.
- A subscriber can subscribe to multiple topics. Each subscriber is identified by unique id(alphanumeric).
- Publisher can specify
TTL
(Time-to-live) while publishing a message to particular topic. So a message(withttl = t secconds
) will expire aftert
seconds. - A message is published on a topic(
T
) will be delivered to each subscriber of that topic(T
) exactly once. - If a subscriber goes down for a duration(
D
), then all the pending messages(withTTL > D
) will be delivered to that subscriber once it comes back alive after duration(D
). - Publisher & subscriber(s) needs to connect to Redis.
- Each & every subscriber must be assigned a unique id.