FCMicroservices 0.4.0.12
dotnet add package FCMicroservices --version 0.4.0.12
NuGet\Install-Package FCMicroservices -Version 0.4.0.12
<PackageReference Include="FCMicroservices" Version="0.4.0.12" />
paket add FCMicroservices --version 0.4.0.12
#r "nuget: FCMicroservices, 0.4.0.12"
// Install FCMicroservices as a Cake Addin #addin nuget:?package=FCMicroservices&version=0.4.0.12 // Install FCMicroservices as a Cake Tool #tool nuget:?package=FCMicroservices&version=0.4.0.12
Creating New Microservice
The following service package should be connected to a newly created service. First create a brand new web-api application in your ide. Then install this nuget.
nuget install fc.micro.services
Program.cs
A minimum start can be made to the Program.cs file as follows. The dbcontext needed by the microservice is given and it is run with Run() method. By default, the connection string is tried to be retrieved by searching for a key called "DB".
Microservice
.Create(args)
.UseDbContext<HelloWorldDbContext>()
.Run();
Events / Subcriptions
If we want the service to listen to an event, a code like the one below will suffice. It listens for
the CalculationFinished
event and executes CalculationFinishedSubscription
when it receives the message.
Microservice
.Create(args)
.WithSubscription<CalculationFinished>()
.Run();
Sample Event:
using fc.micro.services.Core.Microservice.Components.BUS.Events;
namespace fc.micro.services.Hello.Microservice.Messages.Events
{
[Event]
public class CalculationFinished
{
public int Result { get; set; }
}
}
Sample Event Subscription:
using fc.micro.services.Core.Microservice.Components.BUS.Events;
using fc.micro.services.Core.Microservice.Extensions;
namespace fc.micro.services.Hello.Microservice.Messages.Events
{
public class CalculationFinishedSubscription : EventSubscription<CalculationFinished>
{
public override void OnEvent(CalculationFinished input)
{
Console.WriteLine("Message received!" + input.ToJson(true));
}
}
}
Probe'lar
We understand the status of a service with probes. The following are the default values. Here is an example of the code that says I am healthy in any case. Probes are used during virtualization. Configure Liveness, Readiness and Startup Probes | Kubernetes
Liveness http://localhost:5000/liveness
- There may be cases where a pod opens very slowly. Killing with Liveness is prevented. If Liveness is false, it will be deleted and restarted.
Readiness http://localhost:5000/readiness
- This service allows you to decide whether to receive a request or not. It cannot be done. Shall I provide request traffic to the pod? says kubernetes
Startup http://localhost:5000/startup
- It allows to query whether the application is ready or not. Liveness and readiness are treated as false in the startup = false case. If everything is ok, Kubernetes deploys the pod to the network.
Microservice
.Create(args)
.WithProbes(x => x
.SetLiveness<DefaultLivenessHealthCheck>()
.SetReadiness<DefaultReadinessHealthCheck>()
.SetStartup<DefaultStartupHealthCheck>()
)
.Run();
IConfigLoader
With ConfigLoader, it is provided to get settings first from environment and then from appsettings.
var a = IConfigloader.Load ("a", "1");
In the above case, if the a variable is passed in appsettings, it takes the value there. It is useful for us when debugging while working in local.
{
"a" : 200
}
The variable a is overwritten to 200. If it is not in appsettings, it may come from environment. This happens mostly with docker run.
docker run microservice -e a 100
The variable a will be crushed to 100 in the environment it is running.
The default value of 1 is the value to be assigned if nothing is found. It is optional, if it is not given, it means no default value. And we force it to be in env and appsettings.
Settings for api
use_pubsub : "yes" / "no"
use_tracer : "yes" / "no"
Components to be used in appsettings.json can be determined. If Event/Subscription is to be used, use_pubsub must be marked yes. If trace is to be done, use_tracer must be yes in the same way.
"use_pubsub": "yes",
"use_tracer": "yes"
Kestrel Endpoints
To change the endpoints, the Kestrel part in appsettings.json can be given as follows. Which ports are required for GRPC and HTTP.
"Kestrel": {
"Endpoints": {
"http": {
"Url": "http://0.0.0.0:5000",
"Protocols": "Http1"
},
"grpc": {
"Url": "http://0.0.0.0:5001",
"Protocols": "Http2"
}
}
},
When the Console application runs, it will give an output like the one below.
PROBES
=========================
{
"liveness": null,
"readiness": null,
"startup": null
}
subscribing... HesaplamaBitti
SUBSCRIPTIONS
=========================
[
"HesaplamaBitti"
]
ConfigLoader
=========================
{
"DB": "Host=localhost;Database=hello-microservice;Port=5432;Username=postgres;Password=1234",
"use_pubsub": "yes",
"use_tracer": "yes",
"PUBSUB_URL": "http://localhost:4222",
"LOG_COLLECTOR": "http://localhost:14268",
"LOG_AGENT": "localhost",
"LOG_AGENT_PORT": "6831"
}
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'http://localhost:5000'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://0.0.0.0:5001
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://0.0.0.0:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\repos\microservice\hello.microservice\
Enterprise Service BUS
We run commands and queries with the bus. When we need to throw an event, we can broadcast or look at the result of another service with BUSClient.
Command:
Query:
Event:
Dependency injection in Handlers
service inspection with api/info
BUS usage
Publisher usage on BUS
Connecting other micro-services to the microservice
In order to include and call messages from other microservices in the project, the following package must be installed.
nuget install [TODO:MicroMessages]
BUS and BUSClient example
Docker microservice and send to harbor
Using one (more than one) dockerized service on the same machine
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- EFCore.NamingConventions (>= 7.0.0)
- Google.Protobuf (>= 3.21.12)
- Google.Protobuf.Tools (>= 3.21.12)
- Grpc.AspNetCore (>= 2.51.0)
- Grpc.AspNetCore.Server.Reflection (>= 2.51.0)
- HotChocolate.Language (>= 13.0.5)
- Microsoft.AspNet.WebApi.Client (>= 5.2.9)
- Microsoft.AspNet.WebApi.Core (>= 5.2.9)
- Microsoft.AspNet.WebApi.WebHost (>= 5.2.9)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 7.0.4)
- Microsoft.AspNetCore.Grpc.HttpApi (>= 0.1.0-alpha.21317.5)
- Microsoft.AspNetCore.Grpc.Swagger (>= 0.3.4)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 7.0.4)
- Microsoft.AspNetCore.StaticFiles (>= 2.2.0)
- Microsoft.EntityFrameworkCore (>= 7.0.4)
- NATS.Client (>= 1.0.3)
- Newtonsoft.Json (>= 13.0.2)
- NJsonSchema (>= 10.8.0)
- NJsonSchema.CodeGeneration.CSharp (>= 10.8.0)
- Npgsql (>= 7.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 7.0.1)
- Npgsql.OpenTelemetry (>= 7.0.0)
- NRedisStack (>= 0.11.0)
- OpenTelemetry (>= 1.3.2)
- OpenTelemetry.Exporter.Console (>= 1.3.2)
- OpenTelemetry.Exporter.Jaeger (>= 1.3.2)
- OpenTelemetry.Exporter.Prometheus (>= 1.2.0-rc4)
- OpenTelemetry.Exporter.Zipkin (>= 1.3.2)
- OpenTelemetry.Extensions.Hosting (>= 1.0.0-rc9.1)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.0.0-rc9.1)
- OpenTelemetry.Instrumentation.GrpcNetClient (>= 1.0.0-rc9.1)
- OpenTelemetry.Instrumentation.Http (>= 1.0.0-rc9.1)
- OpenTelemetry.Instrumentation.SqlClient (>= 1.0.0-rc9.1)
- Redis.OM (>= 0.6.1)
- Swashbuckle (>= 5.6.0)
- Swashbuckle.AspNetCore (>= 6.5.0)
- Swashbuckle.AspNetCore.ReDoc (>= 6.5.0)
- Swashbuckle.AspNetCore.Swagger (>= 6.5.0)
- ToMarkdownTable (>= 0.2.1-alpha0003)
- YamlDotNet (>= 13.7.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.4.0.12 | 286 | 7/11/2024 |
0.4.0.11 | 3,326 | 4/26/2024 |
0.4.0.10 | 53 | 4/26/2024 |
0.4.0.9 | 62 | 4/26/2024 |
0.4.0.8 | 148 | 4/25/2024 |
0.4.0.7 | 61 | 4/25/2024 |
0.4.0.6 | 399 | 4/4/2024 |
0.4.0.5 | 1,459 | 3/4/2024 |
0.4.0.4 | 69 | 3/4/2024 |
0.4.0.3 | 557 | 2/16/2024 |
0.4.0.2 | 71 | 2/16/2024 |
0.4.0.1 | 66 | 2/15/2024 |
0.4.0 | 96 | 2/10/2024 |
0.3.20.9 | 249 | 1/29/2024 |
0.3.20.8 | 62 | 1/29/2024 |
0.3.20.7 | 1,029 | 1/16/2024 |
0.3.20.6 | 261 | 1/9/2024 |
0.3.20.5 | 85 | 1/8/2024 |
0.3.20.4 | 120 | 1/8/2024 |
0.3.20.3 | 104 | 1/6/2024 |
0.3.20.2 | 99 | 1/2/2024 |
0.3.20.1 | 88 | 1/2/2024 |
0.3.10.100 | 769 | 12/8/2023 |
0.3.10.10 | 93 | 11/26/2023 |
0.3.10.9 | 71 | 11/26/2023 |
0.3.10.8 | 873 | 11/13/2023 |
0.3.10.7 | 74 | 11/10/2023 |
0.3.10.5 | 74 | 11/10/2023 |
0.3.10.4 | 316 | 11/7/2023 |
0.3.10.3 | 377 | 11/4/2023 |
0.3.10.2 | 86 | 11/4/2023 |
0.3.10.1 | 93 | 11/1/2023 |
0.3.10 | 87 | 10/31/2023 |
0.3.9.20 | 617 | 10/25/2023 |
0.3.9.19 | 104 | 10/24/2023 |
0.3.9.18 | 411 | 10/14/2023 |
0.3.9.17 | 361 | 10/8/2023 |
0.3.9.16 | 101 | 10/8/2023 |
0.3.9.15 | 882 | 8/27/2023 |
0.3.9.14 | 1,522 | 7/4/2023 |
0.3.9.13 | 106 | 7/4/2023 |
0.3.9.12 | 127 | 5/1/2023 |
0.3.9.11 | 814 | 4/8/2023 |
0.3.9.10 | 186 | 4/2/2023 |
0.3.9.9 | 197 | 3/31/2023 |
0.3.9.8 | 168 | 3/27/2023 |
0.3.9.7 | 414 | 3/25/2023 |
0.3.9.6 | 157 | 3/25/2023 |
0.3.9.5 | 141 | 3/24/2023 |
0.3.9.4 | 136 | 3/24/2023 |
0.3.9.3 | 182 | 3/23/2023 |
0.3.9.2 | 124 | 3/23/2023 |
0.3.9.1 | 126 | 3/23/2023 |
0.3.9 | 149 | 3/22/2023 |
0.3.8 | 136 | 3/22/2023 |
0.3.7 | 321 | 2/27/2023 |
0.3.6 | 653 | 2/15/2023 |
0.3.5 | 138 | 2/15/2023 |
0.3.3 | 306 | 1/30/2023 |
0.3.2.1 | 68 | 1/2/2024 |
0.3.2 | 173 | 1/29/2023 |
0.3.1 | 145 | 1/29/2023 |
0.0.3 | 146 | 1/28/2023 |
0.0.2.1 | 150 | 1/29/2023 |
0.0.2 | 297 | 1/23/2023 |