Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example project on how to combine Docker with ZeroMQ for micro-services #1321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NumesSanguis
Copy link
Contributor

Docker allows for deploying services on any system without going through the trouble of installing packages or any compiling.
ZeroMQ + Docker are a natural fit for creating micro-services by having multiple Docker containers communicate with each other over ZMQ.
This project contains an example Publisher-Subscriber that can be set-up in a Python-Python, Docker-Docker and Docker-Python fashion, without any code changes.

It is a copy from my repository: https://github.com/NumesSanguis/pyzmq-docker
It is BSD licensed.

Hope it can be useful for fellow ZeroMQ/PyZMQ folks :)

@NumesSanguis
Copy link
Contributor Author

Could someone explain me why AppVeyor failed with this?:

start /W pytest -vsx -m "new_console" --pyargs zmq.tests --junit-xml=../results.xml
python ../tools/check_junit_result.py ../results.xml
No tests run
Command exited with code 1

print("Going to connect to: {}".format(url))
ctx = zmq.Context()
socket = ctx.socket(zmq.PUB)
socket.connect(url) # publisher connects to subscriber
Copy link

@bunkerdives bunkerdives Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't publisher => socket.bind? And likewise, the subscriber would socket.connect?

Copy link
Contributor Author

@NumesSanguis NumesSanguis Jan 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for checking @JSalazar88. I agree that it's more common that a single Publisher sends message to multiple Subscribers, but with ZMQ it is also possible to have a single Sub wait for messages from multiple Pubs.
In the example code, there is only 1 Pub and 1 Sub, so it doesn't really matter which socket connects and which one binds. This example is now setup as a m-Pub to 1-Sub pattern. Could be changed, but it won't change anything for the functioning of this example.

context: ./sub # Docker context from folder of this file; needed to include requirement.txt
dockerfile: Dockerfile
ports:
- "5550:5550" # map container interal 5550 port to publicly accessible 5550 port
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 5550 and not 5551 as the defaults would suggest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been a while ago I wrote this, but I think I did this so you could both test the Docker and non-Docker version at the same time. If the port value is the same, and you start them both, one of the 2 cannot bind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants