(3) The surging microservice framework uses the series of my first services (audit logs) and the surging framework
After so long preparation, we can finally build our own services. This blog will let us build our first service, audit logs.
First, we will create two projects: a console service startup project and a business implementation project. (Note: The console project can reference business projects, or do not reference business projects. Because surging supports hot deployment)
Reference the surging components we need in the service startup project,
Service Configuration:
Of course, the configuration of rabbitmq as described earlier :.
OK. The code for our Service is compiled. Note that the Service name must end with "Service" and the Service interface must inherit the IServiceKey.
Service implementation:, ModuleName (""), because an interface may have multiple implementations, The ModuleName here is to distinguish which implementation we will use when calling, if there is only one implementation, you don't need this attribute. In addition, the implementation only needs to inherit the service interface defined by ProxyServiceBase and yourself.
Note that the surging interface does not support generics. The encoding method uses json to transmit data. The method parameter name is required when the client calls the method.
Client: first, the client adds the surging component we need in nuget,
Client configuration: Of course, the configuration of rabbitmq cannot be missing.
In the client, you only need to configure the rabbitmq connection address.
Test code:, get the proxy instance, client service call test code :,
Set audit logs and clients as startup projects :,
Test result: the call is successful.
Surging microservice framework: it is officially recommended that UseMessagePackCodec be used as the encoding method. The call efficiency is around milliseconds (calling the interface must be referenced (obtaining the proxy instance ServiceLocator. GetService <IServiceProxyFactory> ())).
In this blog, I use the json encoding method. The calls to the surging test are around Ms.
Uses json encoding to call await proxy between services. invoke <object> (model, "api/userManager/singleByEmailAndPassword", "User"); is implemented using this code.