Example project on how to combine Docker with ZeroMQ for micro-services#1321
Example project on how to combine Docker with ZeroMQ for micro-services#1321NumesSanguis wants to merge 1 commit intozeromq:mainfrom
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.
Shouldn't publisher => socket.bind? And likewise, the subscriber would socket.connect?
There was a problem hiding this comment.
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.
why 5550 and not 5551 as the defaults would suggest?
There was a problem hiding this comment.
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 :)