A microservice project using .NET Core 2.0, DDD, CQRS, Event Sourcing, Redis and RabbitMQ.
Components
System Architecture
Prerequisites
Visual Studio 2017 (For development and debug propose)
RabbitMQ
Redis
Consul (Service Discovery and registeration)
Consult Template (Update and Restart Nginx)
Nginx (For Load Balance)
MongoDB (For Event Store)
EDA
Service Discovery
We will use the Nginx, Consul, Consul Template to create an service discovery and service registeration mechanism.
The nginx will do the load balance work.
All the web or api instances will be registered in the consul server with the SelfRegister method.
Consul template will listen the consul server, if there is new instance, consul template will update the nginx.conf with assigned template and restart the nginx server, so the new instance will be connected with the nginx server correctly
Use the Log service as an example.
public void SelfRegister()
{
var serviceDiscovery = InjectContainer.GetInstance<IServiceDiscovery>();
serviceDiscovery.RegisterService(new Infrastructure.Operation.Core.Models.Service
{
Port = 5003,
ServiceName = "LogService",
Tag = "Microservice API"
});
Console.WriteLine("Register to consul successfully.");
}
请发表评论