Service Registry Pattern — Netflix Eureka Server With Steeltoe & .NetCore & PCF

RamanaReddy V
5 min readMar 6, 2021

--

Service Registry provides your apps with an implementation of the Service Discovery pattern, one of the key tenets of a microservice-based architecture. Trying to hand-configure each client of a service or adopt some form of access convention can be difficult and prove to be brittle in production. Instead, your apps can use the Service Registry to dynamically discover and call registered services.

When a client registers with the Service Registry, it provides metadata about itself, such as its host and port. The Registry expects a regular heartbeat message from each service instance. If an instance begins to consistently fail to send the heartbeat, the Service Registry will remove the instance from its registry.

Why Service Registry:

In microservices architecture patterns we have lot of microservices in place from different sources (i.e. Different Hostnames & dynamic ports). To manages those service contracts is very difficult. To overcome this problem service registry come into picture.

Use Case:

Sample Use case for Service Discovery pattern

Prerequisites:
1. PCF account (i.e. PCF part of VMware Tanzu https://login.run.pivotal.io/login It may differ )
2. CF CLI Installation(i.e. https://docs.run.pivotal.io/cf-cli/install-go-cli.html ) Windows Platform choice.
3. .Net 5 with Blazor Framework (i.e. we can choose lower versions also )
4. steeltoe Packages from NuGet
5. Within PCF we need Service Registry service in marketplace.
6. Create a .net core supported version of build packs with in PCF.

Step 1:

Install CF CLI on your windows ENV (i.e. https://docs.pivotal.io/pivotalcf/2-3/cf-cli/install-go-cli.html ) & set path for CF CLI. Login to CF CLI through CMD by using your PCF account API (i.e. go to Tools option in your PCF ENV). After login choose your org & space.

CF CLI Installation on Windows

Step 2:
Create a Service Registry service within your space by using CF CLI like below
( i.e. https://docs.pivotal.io/spring-cloud-services/3-1/common/service-registry/managing-service-instances.html )

cf create-service p.service-registry standard myDiscoveryService ( i.e. Spring Cloud Services)

OR

cf create-service p-service-registry standard myDiscoveryService  // According to steeltoe Doc

Step 3:
Create a Sample web api project (i.e. M_Service1) by using Visual studio like below.

M_Service1

Add below NuGet packages.

NuGet for M_Service1

Update Program.cs file like below.

program.cs for M_Service1

Add sample method in WeatherForecastController.cs

Sample method in M_Service1

Add manifest.yml file into M_Service1 Web API project and update file according to your PCF deployment. Here very basic level configuration on PCF env deployment like below. myDiscoveryService service will bind the Micro_Service_1 application after deploying into PCF.

manifest.yml in M_Service1

Update the appsettings.Development.json file like below

Appsettings in M_Service1

we can set “ShouldFetchRegistry”: false bcz we’re registering M_Service1 API into Eureka server. EurekaServerServiceUrls automatically updated with bound the service URL with help of steeltoe lib’s after deployment into PCF env.
For more Eureka config settings refer following link https://docs.steeltoe.io/api/v3/discovery/netflix-eureka.html

Step 4:

Publish the M_Service1 API into PCF by using CF CLI . If you’re using CI/CD pipeline means we need to configure according to pipeline rules.

For now we can deploy through manual by using CF CLI.
a. Publish M_Service1 API into any local directory (i.e. C:\MS1\). Make sure manifest.yml should be in published location.
b. Login CF CLI & select corresponding Space with help of CMD.
c. After login into PCF navigate to published location within same CMD CF CLI login session (i.e. cd C:\MS1 )
d. After navigated into published location M_Service1 API then type cf push
e. You’re able to see deployment completed status logs of PCF in CMD.

Step 5:
Login into you’re PCF account you’re able see your deployed app within DEV space.

DEV space Home page in PCF

Go to Micro_Service_1 App you’re able see dashboard like below & Go to Service option. In service option page you’re able to see you’re registered service app.

Micro_Service_1 Dashboard
Bound Service page within Micro_Service_1
List of Applications bound to myDiscoveryService
Registered Apps within Eureka server (i.e. myDiscoveryService)

Step 6:

Repeat the above Step 3 to Step 5 for M_Service2 web API also.

Step 7:
For client application I selected as Blazor framework App (i.e. BlazordemoUI).

basic client application look like below

BlazordemoUI

Add below NuGet packages :

NuGet for BlazordemoUI

Update Program.cs file like below

Program.cs for BlazordemoUI

Update the Startup.cs file like below

ConfigureServices method for BlazordemoUI
Configure method for BlazordemoUI

Add simple Blazor pages like below for M1 service & M2 service.

M1service.razor page

Update Ms1 & Ms2 service like below :

Ms1 service

Update Appsettings.json (i.e. Proper ENV) like below

Appsettings

Make sure APIContracts Ms1 & Ms2 should be match with Eureka server Application name like below.

Eureka server

Update manifest.yml like below

manifest.yml for BlazordemoUI

Repeat Step 4 & Step 5 for deployment into PCF.

References :
1.
https://docs.pivotal.io/spring-cloud-services/3-1/common/service-registry/index.html

2. https://steeltoe.io

3. https://microservices.io/patterns/service-registry.html

Note:

I’m sharing this as per my knowledge. Anywhere, I did wrong. please let me know. I want to update myself.

=============== Happy Coding ===============

--

--

RamanaReddy V
RamanaReddy V

No responses yet