bkromrey / recipe-search

0 stars 0 forks source link

This is a small microservice that can be used to identify recipes that meet specific search criteria. \ \ This microservice is designed to be run on the same local machine as the client that is communcating with it. It communicates via ZeroMQ on port 5555, which is declared as a constant at the top of main.go should you need to change this port. You should be able to stop this microservice by via ctrl+c or sending 'q' as a request_type.

Running the Microservice

Clone or download the repository and then use go run main.go

Requesting Data

When making a request of this microservice, you must send your request as a JSON dictionary object that includes three components:

The sample.json file contains an example of a valid recipe_db.

Create your ZeroMQ pipe.

PORT = 5555
context = zmq.Context()
socket = context.socket(zmq.REQ)
address_to_connect = "tcp://localhost:" + str(PORT)
socket.connect(address_to_connect)

Here is an example of what requesting data might look like:

user_query = input("ingredient(s) to search for: ")

data_for_request = {
    "request_type" : "QueryByRecipeIngredients",
    "user_query": user_query,
    "recipe_db": db
}

socket.send_json(data_for_request)

Receiving Data

This microservice will send back a JSON object that is a list containing recipe dictionaries, where each recipe in this list matched the search criteria. If no results were found, this microservice will send back an empty list.

Data is received from the same ZeroMQ socket that it was requested on, on port 5555 (or if you changed the value of the constant at the top of main.go then whatever port you chagned it to).

Here is an example of how to receive data:

response = socket.recv()
decoded_response = response.decode()
print(f"response from server: {decoded_response}\n\n")

UML Diagram

image