Skip to content
Snippets Groups Projects

Simpleservices

Open Sastry, Nishanth Prof (Comp Sci & Elec Eng) requested to merge simpleservices into master
Files
2
+ 23
2
@@ -10,6 +10,10 @@ python3 movies.py
```
Now, the movies microservice is running. You can query it by sending HTTP GET requests. Note that we are using the port 5001 on localhost (127.0.0.1) as that is how the server is configured (see towards the bottom of the file in movies.py)
```console
python3 movies.py
```
Now, the movies microservice is running. You can query it by sending HTTP GET requests. Note that we are using the port 5001 on localhost (127.0.0.1) as that is how the server is configured (see towards the bottom of the file in movies.py)
```console
curl http://127.0.0.1:5001/ #returns list of endpoints exposed
curl http://127.0.0.1:5001/movies #returns list of all movies
curl http://127.0.0.1:5001/movies/720d006c-3a57-4b6a-b18f-9b713b073f3c #returns details of one movie
@@ -21,6 +25,10 @@ python3 showtimes.py
```
You can query its endpoints too:
```console
python3 showtimes.py
```
You can query its endpoints too:
```console
$ curl 127.0.0.1:5002/
{"uri": "/", "subresource_uris": {"showtimes": "/showtimes", "showtime": "/showtimes/<date>"}}%
$ curl 127.0.0.1:5002/showtimes
@@ -47,11 +55,24 @@ $ curl 127.0.0.1:5002/showtimes/20151130
"Spectre"
]%
```
>Try your best to solve it. If you need hints, you will find the solution for this in the branch `simpleservices`, which you can obtain by running `git checkout simpleservices`. Note that after checking out this branch, you will have to start both the `movies` and `showtimes` microservices and then issue the curl request. The showtimes microservice will talk to movies microservice to deliver the final result.
> This tutorial is continued now in the `simpleservices` branch
The main change needed is simple. We just have to issue an HTTP GET request to the movies API endpoint. We do this by changing `showtime_record` as follows:
```python
movies_service = "http://127.0.0.1:5001/movies/{}" #we know this is where the service is running. We replace the {} with the actual ID of the movie we want.
def showtimes_record(date):
if date not in showtimes:
raise NotFound
print(showtimes[date])
result = []
for movie_id in showtimes[date]:
resp = requests.get(movies_service.format(movie_id))
result.append(resp.json()["title"])
return nice_json(result)
```
## Step 3: Dockerization of microservices
> We now have two microservices running on _localhost_ and talking to each other. If we need to move these services, it is not easy.
> Your next task is to wrap these microservices as a docker image and make them portable. Essentially, this involves specifying all the dependencies and running parameters explicitly in a `Dockerfile`. You can have a go at this by copying from this [tutorial](https://www.docker.com/blog/containerized-python-development-part-1/). Or, switch to the `dockerservices` branch where you will find the solution for steps 3 and 4.
## Step 4: How to make two dockerized microservices talk to each other
Loading