-
Notifications
You must be signed in to change notification settings - Fork 635
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
base: main
Are you sure you want to change the base?
Conversation
Could someone explain me why AppVeyor failed with this?:
|
print("Going to connect to: {}".format(url)) | ||
ctx = zmq.Context() | ||
socket = ctx.socket(zmq.PUB) | ||
socket.connect(url) # publisher connects to subscriber |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 :)