Question: The second part has a subscriber and a publisher again running from your local computer with the docker image efrecon/mqtt-client. By using as many as


The second part has a subscriber and a publisher again running from your local computer with the docker image efrecon/mqtt-client. By using as many as necessary Python scripts you have to publish/subscribe to the above mqtt broker. The topic has to be "alfaisal_uni" and the messages have to be > where XX will be an increasing counter. Send and receive as many messages as you need to exhibit the above implementation. a. Deploy a service named "subscriber" with three (3) replicas of the efrecon/mqtt-client docker image b. Deploy a service named "publisher" with three (3) replicas of the efrecon/mqtt-client docker image c. You will also have to configure the services to automatically restart (always) d. Your code should print out the names, IDs, and number of running replicas of both server and client services. e. Start publishing messages to the broker, so your code can show how multiple subscriber replicas subscribe to the same topic of multiple broker replicas and multiple publisher replicas send multiple messages. Do craft your messages as you wish (e.g., 1.1.1) to exhibit the above random behaviours. Make all your code run for a set amount of time (e.g., 5 minutes), sends a number of messages, and then shut down cleanly, cleaning up after itself to bring down services, remove the overlay network, and finally tear down the Docker Swarm(s). IP address 172.17.0.1 for the -h option. BE CAREFUL: localhost and 127.0.0.1 do not seem to work (You get bonus if you find out how to make them work!) Example commands of suscribe/publish follow: docker run -it --rm efrecon/mqtt-client sub -h host.docker.internal:1888 -t "george" -v docker run -it --rm efrecon/mqtt-client pub -h 172.17.0.1-p 1883 -t "topic" -m "message" To run docker in Python, a fully functional minimal code for running the Ubuntu docker follows (Notice that there is also error handling which is highly suggested for easy debugging): import docker from docker.errors import DockerException try: client = docker.from_env() client.containers.run ("ubuntu:latest", "sleep infinity", detach=False) print("All containers: ", client.containers.list()) print("container id: ", container.id) except (DockerException) as e: print(str(e))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
