Microservices Architecture Journal!
Microservices Architecture Journal!
ON
MICROSERVICES ARCHITECTURE
FOR
UNIVERSITY OF MUMBAI
SUBMITTED BY
2021-2022
CONDUCTED AT
NIRMALA MEMORIAL FOUNDATION COLLEGE
OF
PRACTICAL 1
Building ASP .NET CORE MVC APPLICATION
1
Mahima_Yogeeswarar_MscIT_MA_8
2
Mahima_Yogeeswarar_MscIT_MA_8
Save the modified file, Now go to cmd and type dotnet run to run the
project
3
Mahima_Yogeeswarar_MscIT_MA_8
4
Mahima_Yogeeswarar_MscIT_MA_8
5
Mahima_Yogeeswarar_MscIT_MA_8
Practical 2
Building ASP.Net core Rest API
Install Required Software
Visual studio
Dotnet sdk
Now go to the Glossary directory and try to run dotnet run to see it runs
successfully
cd Glossary
Dotnet run
Now delete the weatherforecast files and add the Glossary file i.e
GlossaryItem.cs in glossary folder and GlossaryController in Controllers
folder
6
Mahima_Yogeeswarar_MscIT_MA_8
GlossaryItem.cs
namespace Glossary
{
public class GlossaryItem
{
public string Term{get;set;}
public string Definition{get;set;}
}
}
GlossaryController.cs
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.IO;
namespace Glossary.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class GlossaryController:ControllerBase
{
private static List<GlossaryItem>Glossary=new
List<GlossaryItem>{
new GlossaryItem
{
Term="HTML",
Definition="HyperText Markup language"
},
new GlossaryItem
{
Term="MVC",
Definition="Model View Control"
},
new GlossaryItem
{
Term="OpenID",
Definition="An Open Standard For
Autehntication"
}
};
[HttpGet]
public ActionResult<List<GlossaryItem>>Get()
7
Mahima_Yogeeswarar_MscIT_MA_8
{
return Ok(Glossary);
}
[HttpGet]
[Route("{term}")]
public ActionResult<GlossaryItem>Get(string term)
{
var
glossaryItem=Glossary.Find(item=>item.Term.Equals(term,StringCompa
rison.InvariantCultureIgnoreCase));
if(glossaryItem==null)
{return NotFound();
}else
{
return Ok(glossaryItem);
}
}
[HttpPost]
public ActionResult Post(GlossaryItem glossaryItem)
{
var
existingGlossaryItem=Glossary.Find(item=>item.Term.Equals(glossaryIt
em.Term,StringComparison.InvariantCultureIgnoreCase));
if (existingGlossaryItem!= null)
{
return Conflict("Cannnot create the term because it already
exists");
}
else
{
Glossary.Add(glossaryItem);
var
resourseUrl=Path.Combine(Request.Path.ToString(),Uri.EscapeUriString
(glossaryItem.Term));
return Created(resourseUrl,glossaryItem);
}
}
[HttpPut]
public ActionResult Put(GlossaryItem glossaryItem)
{
8
Mahima_Yogeeswarar_MscIT_MA_8
var
existingGlossaryItem=Glossary.Find(item=>item.Term.Equals(glossaryIt
em.Term,StringComparison.InvariantCultureIgnoreCase));
if (existingGlossaryItem==null)
{
return BadRequest("Cannnot update a non existing Term");
}
else
{
existingGlossaryItem.Definition=glossaryItem.Definition;
return Ok();
}}
[HttpDelete]
[Route("{term}")]
public ActionResult Delete(string term)
{
var
glossaryItem=Glossary.Find(item=>item.Term.Equals(term,StringCompa
rison.InvariantCultureIgnoreCase));
if(glossaryItem==null)
{return NotFound();
}else
{
Glossary.Remove(glossaryItem);
return NoContent();
}
}
}
}
Output
This Display the Items in the Glossary
curl --insecure https://localhost:5001/api/glossary
9
Mahima_Yogeeswarar_MscIT_MA_8
10
Mahima_Yogeeswarar_MscIT_MA_8
Practical No : 3
Working with Docker, Docker Commands, Docker
images and Container
Visit to docker website and sign up
Now signIn
11
Mahima_Yogeeswarar_MscIT_MA_8
12
Mahima_Yogeeswarar_MscIT_MA_8
13
Mahima_Yogeeswarar_MscIT_MA_8
Docker --version type this command to check the versiom of the docker
14
Mahima_Yogeeswarar_MscIT_MA_8
Click on create
15
Mahima_Yogeeswarar_MscIT_MA_8
16
Mahima_Yogeeswarar_MscIT_MA_8
17
Mahima_Yogeeswarar_MscIT_MA_8
Practical 4
Docker Desktop Installation
https://www.docker.com/products/docker-desktop
18
Mahima_Yogeeswarar_MscIT_MA_8
Click On OK
19
Mahima_Yogeeswarar_MscIT_MA_8
Click on ohk
Now You will get a Prompt say install WSL2 is incomplete click on the
link which is given in prompt
20
Mahima_Yogeeswarar_MscIT_MA_8
Click on the WSL2 Linux kernal update package package for x64
machines the will download wsl_update_x64.exe and run it
Now open Docker Desktop you will be able to see Docker Engine Getting
Started
21
Mahima_Yogeeswarar_MscIT_MA_8
22
Mahima_Yogeeswarar_MscIT_MA_8
You Will able to the Docker Pulling and downloading the the images and
Container
23
Mahima_Yogeeswarar_MscIT_MA_8
Now You can see Containers in the Docker Deskstop which we have just
downloaded using CMD by copy the Command from docker
24
Mahima_Yogeeswarar_MscIT_MA_8
Enter Your ID and Password if you don’t have then create it from
hub.docker.com
25
Mahima_Yogeeswarar_MscIT_MA_8
Practical 5
Working With Docker Swarm
Check the Version of the docker by running docker version in docker
playground
26
Mahima_Yogeeswarar_MscIT_MA_8
Copying the docker swarm join command from node1 to node2 your
node2 will be joined with node 1 as worker
Go to node 1 and check the output you can see the node1 manager status
as leader and node1 and node2 active in the list
27
Mahima_Yogeeswarar_MscIT_MA_8
Practical 6
Creating Microservices with ASP.NET Core
28
Mahima_Yogeeswarar_MscIT_MA_8
Enable HTTPS and Docker if you have Docker and Keep Docker OS as Linux
29
Mahima_Yogeeswarar_MscIT_MA_8
Open Startup.cs and Change the hello world statement at line 35 if you want as shown
30
Mahima_Yogeeswarar_MscIT_MA_8
Open Program.cs and just verify it and start running your project
After running the project you will See in your docker desktop a container will be created in the name of
your project
31
Mahima_Yogeeswarar_MscIT_MA_8
Create new project of asp.net core web api and and give a name
32
Mahima_Yogeeswarar_MscIT_MA_8
Enable docker also enable OPen API if you get the check box in your VS2019
33
Mahima_Yogeeswarar_MscIT_MA_8
You will be able to see Progrram.cs file startup.cs file and weatherforecast.cs file
34
Mahima_Yogeeswarar_MscIT_MA_8
Practical No7
Creating Backing Services with ASP.NET Core
We need to open 3 command prompts
(On command prompt 1 start location service)
Command : to run location service (go inside project folder first)
dotnet run --server.urls http://*:5000
output:
35
Mahima_Yogeeswarar_MscIT_MA_8
curl https://localhost:5001/teams/e52baa63-d511-417e-9e54-
7aab04286281/members/63e7acf8-8fae-42ce-9349-3c8593ac8292
36