You are on page 1of 38

PRACTICAL REPORT

ON

MICROSERVICES ARCHITECTURE

FOR

UNIVERSITY OF MUMBAI

SUBMITTED BY

YOGEESWARAR MAHIMA ALAGIAH


M.SC (INFORMATION TECHNOLOGY) PART-1 SEMESTER-II

2021-2022

CONDUCTED AT
NIRMALA MEMORIAL FOUNDATION COLLEGE

OF

COMMERCE AND SCIENCE

D.S. Road, Thakur Complex, Kandivali East, Mumbai 400 101


INDEX
SR. No. Content Page No Sign

1 Building ASP.NET core MVC Application 1-5

Building ASP.NET core Rest API 6-10


2

Working with Docker,Docker commands


3 11-17
and docker images
4 Decker Desktop installation 18-25
5 Working with docker swarm 26-27
6 Creating microservices with ASP.NET core 28-34
Creating Backing Services with ASP.NET
7 35-36
Core
Mahima_Yogeeswarar_MscIT_MA_8

PRACTICAL 1
Building ASP .NET CORE MVC APPLICATION

INSTALL .NET CORE SDK

Go to the link and click on download .net sdk and install it


https://dotnet.microsoft.com/learn/dotnet/hello-world-tutorial/install

Create a folder pract i.e “E:\Mahima_8\pract”

Go to pract folder in cmd and run the command


dotnet new mvc --auth none creates a dotnet core project with no
authentication

1
Mahima_Yogeeswarar_MscIT_MA_8

Now open pract folder you will see some files

Now open Controllers folder and edit HomeController.cs as shown

2
Mahima_Yogeeswarar_MscIT_MA_8

Save the modified file, Now go to cmd and type dotnet run to run the
project

Now open the browser and type the URL localhost:5001

Go cmd, Ctrl+C to shut down the application

3
Mahima_Yogeeswarar_MscIT_MA_8

Go to E:\Mahima_8\pract\Models and add new file name StockQuote.cs


and start coding as shown

Go to E:\Mahima_8\pract\Views\Home and modify index.cshtml as


shown

4
Mahima_Yogeeswarar_MscIT_MA_8

Now go to E:\Mahima_8\pract\Controllers and edit the


HomeController.cs file as shown

Now run the project by typing dotnet run in cmd

Go to your browser and enter url localhost:5001

5
Mahima_Yogeeswarar_MscIT_MA_8

Practical 2
Building ASP.Net core Rest API
Install Required Software
Visual studio
Dotnet sdk

Create your web API


Command : dotnet new webapi -o Glossary

Now go to the Glossary directory and try to run dotnet run to see it runs
successfully
cd Glossary
Dotnet run

Now open 2nd cmd and type


Curl helps for client server communication
curl --insecure https://localhost:5001/weatherforecast

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

Display a paticular term and its defination


curl --insecure https://localhost:5001/api/glossary/MVC

Insert a term and definition


curl --insecure -X POST -d "{\"term\": \"MFA\",
\"definition\":\"An authentication process.\"}" -H "Content-
Type:application/json" https://localhost:5001/api/glossary

Update the MVC terms definition


curl --insecure -X PUT -d "{\"term\": \"MVC\",
\"definition\":\"Modified record of Model View
Controller.\"}" -H "Content-Type:application/json"
https://localhost:5001/api/glossary

Delete the term OpenID


curl --insecure --request DELETE --url
https://localhost:5001/api/glossary/OpenID

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

This window will get opened

Now go to dockers playground lab and click on start

12
Mahima_Yogeeswarar_MscIT_MA_8

Click on add new instance

This window will get opened

13
Mahima_Yogeeswarar_MscIT_MA_8

Docker --version type this command to check the versiom of the docker

Docker pull rocker/verse this command helps to pull the images

Docker images this show images details

Now create a repository manually

14
Mahima_Yogeeswarar_MscIT_MA_8

Enter the details as shown in the image and make it private

Click on create

15
Mahima_Yogeeswarar_MscIT_MA_8

Now your repository is created

Login from docker CLI

Creating a tag named firsttry using image ID

16
Mahima_Yogeeswarar_MscIT_MA_8

You can also see the tag firsttry

Creating a repository from CLI

17
Mahima_Yogeeswarar_MscIT_MA_8

Practical 4
Docker Desktop Installation

Dowload Docker Desktop from the given link

https://www.docker.com/products/docker-desktop

Run the downloaded Docker Desktop.exe

18
Mahima_Yogeeswarar_MscIT_MA_8

Click On OK

The docker desktop files starts to install

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

Now if you want you can see Tutorial or just Skip it

Check Your Docker is working on Your Pc by copying the command in


docker Desktop

22
Mahima_Yogeeswarar_MscIT_MA_8

You Will able to the Docker Pulling and downloading the the images and
Container

It Might Ask Access 1st time Click on allow access

23
Mahima_Yogeeswarar_MscIT_MA_8

The Container is Download

Now You can see Containers in the Docker Deskstop which we have just
downloaded using CMD by copy the Command from docker

You can also Sign in By Clicking in Sign in

24
Mahima_Yogeeswarar_MscIT_MA_8

Sign in Prompt will appear

Enter Your ID and Password if you don’t have then create it from
hub.docker.com

You will be Signed in

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

Run hello-world for creating a new container called hello-world

26
Mahima_Yogeeswarar_MscIT_MA_8

Creating a docker swarm in node1

Click on Add new instances for Creating node 2

New Instance is created click on node 2

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

Open Visual Studio 2019 Click on Create a new Project

You will See many options

28
Mahima_Yogeeswarar_MscIT_MA_8

Click on ASP.NET Core Empty

Enter name For Your Project and Location

Enable HTTPS and Docker if you have Docker and Keep Docker OS as Linux

29
Mahima_Yogeeswarar_MscIT_MA_8

Your New Project Will be Created

You Will be able to see file


Program.cs
Startup.cs
DockerFile(If you have enabled docker )

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

And the open will be open in the browser

31
Mahima_Yogeeswarar_MscIT_MA_8

B] ASP.NET Core web API

Create new project of asp.net core web api and and give a name

32
Mahima_Yogeeswarar_MscIT_MA_8

Give name to your Project

Enable docker also enable OPen API if you get the check box in your VS2019

33
Mahima_Yogeeswarar_MscIT_MA_8

Your Core Web API Project is created

You will be able to see Progrram.cs file startup.cs file and weatherforecast.cs file

Run the Project

You will be able to see output in browser

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:

(On command prompt 2 start teamservice)


Command : to run teamservice (go inside project folder first)
dotnet run
output:

35
Mahima_Yogeeswarar_MscIT_MA_8

(On command prompt 3 run all following commands) its API


Command to Add new team

curl -H "Content-Type:application/json" -X POST -


d"{\"id\":\"e52baa63-d511-417e-9e54-7aab04286281\",
\"name\":\"KC\"}" http://localhost:5000/teams

Command: to add new member to team


output:
curl -H "Content-Type:application/json" -X POST -d
"{\"id\":\"63e7acf8-8fae-42ce-9349-3c8593ac8292\",
\"firstName\":\"Kirti\", \"lastName\":\"Bhatt\"}"
http://localhost:5000/teams/e52baa63-d511-417e-9e54-
7aab04286281/members

Command To confirm it is accessible from teams

curl https://localhost:5001/teams/e52baa63-d511-417e-9e54-
7aab04286281/members/63e7acf8-8fae-42ce-9349-3c8593ac8292

36

You might also like