This microservice provides a randomized motivational quote in response to a request over a ZeroMQ REQ/REP socket connection.
This microservice uses the ZeroMQ Request/Reply pattern (REQ/REP) over TCP.
- Socket Type: REP (Reply)
- Port:
8765 - Protocol:
tcp://<host>:8765
Once connected, the client sends a plain string message to request a motivational quote. The server responds with a plain string containing a randomly selected quote.
To request a quote, your program must:
- Create a
REQsocket using ZeroMQ. - Connect to the microservice via TCP on port
8765. - Send a string message:
"quote"(or"get quote"or"motivate").
import zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:8765")
socket.send_string("quote") # Request the quoteTo receive the response, your application must:
- Wait for a reply after sending the request.
- Read the string returned by the microservice, which will contain a motivational quote.
quote = socket.recv_string()
print("Received quote:", quote)The microservice accepts the following request strings:
"quote""get quote""motivate"
Any other request string will result in the following error message:
ERROR: Invalid request. Try 'quote' or 'motivate'.
This microservice is designed to return one quote per request. Each request must follow the REQ/REP message pattern exactly.
The diagram below illustrates how the client interacts with the quote microservice using ZeroMQ:
