ZayniFramework.Middle.Service.Client
2.0.1
The Middle.ServiceHost.Client is the client SDK for Middle.ServiceHost module. You can use it to connect, send RPC request or publish message to the Middle.ServiceHost server-side very easy. Support TCPSocket, WebSocket and RabbitMQ protocol.
See the version list below for details.
Install-Package ZayniFramework.Middle.Service.Client -Version 2.0.1
dotnet add package ZayniFramework.Middle.Service.Client --version 2.0.1
<PackageReference Include="ZayniFramework.Middle.Service.Client" Version="2.0.1" />
paket add ZayniFramework.Middle.Service.Client --version 2.0.1
#r "nuget: ZayniFramework.Middle.Service.Client, 2.0.1"
// Install ZayniFramework.Middle.Service.Client as a Cake Addin
#addin nuget:?package=ZayniFramework.Middle.Service.Client&version=2.0.1
// Install ZayniFramework.Middle.Service.Client as a Cake Tool
#tool nuget:?package=ZayniFramework.Middle.Service.Client&version=2.0.1
Middleware ServiceHost.Client example.
You have define your own business logic service by using Middle.ServiceHost module. Now you can use Middle.ServiceHost.Client module to request your service action or trigger a service event to publish a message to your service action.
First, add a serviceClientConfig.json in your client-side app project.
{
"serviceClients": [
{
"serviceClientName": "PaymentServiceProxy",
"remoteServiceName": "PaymentService",
"remoteHostType": "TCPSocket",
"remoteClient": "GCP-Production",
"enableActionLogToDB": true
},
{
"serviceClientName": "OrderServiceProxy",
"remoteServiceName": "OrderService",
"remoteHostType": "RabbitMQ",
"remoteClient": "GCP-Production",
"enableActionLogToDB": true
}
],
"rabbitMQProtocol": {
"defaultRemoteClient": "GCP-Production",
"remoteClients": [
{
"name": "GCP-Production",
"mbHost": "XXX",
"mbPort": 5672,
"mbUserId": "XXX",
"mbPassword": "XXX",
"mbVHost": "SomeHost",
"defaultExchange": "Middle.Test.Topic",
"rpc": {
"exchange": "Middle.Test.Topic",
"routingKey": "RPC.Server.",
"rpcReplyQueue": "Middle.Server.RPC.Res",
"rcpResponseTimeout": 5
},
"publish": {
"exchange": "Middle.Test.Topic",
"routingKey": "Event.Client."
},
"listen": {
"msgQueue": "Middle.Client.ListenServer.Msg",
"msgRoutingKey": "Event.Server."
}
},
{
"name": "Azure-Production",
"mbHost": "XXX",
"mbPort": 5672,
"mbUserId": "XXX",
"mbPassword": "XXX",
"mbVHost": "SomeHost",
"defaultExchange": "Middle.Test.Topic",
"rpc": {
"exchange": "Middle.Test.Topic",
"routingKey": "RPC.Server.",
"rpcReplyQueue": "Middle.Server.RPC.Res",
"rcpResponseTimeout": 5
},
"publish": {
"exchange": "Middle.Test.Topic",
"routingKey": "Event.Client."
},
"listen": {
"msgQueue": "Middle.Client.ListenServer.Msg",
"msgRoutingKey": "Event.Server."
}
}
]
},
"tcpSocketProtocol": {
"defaultRemoteClient": "GCP-Production",
"remoteClients": [
{
"name": "GCP-Production",
"tcpServerHost": "XXX",
"tcpServerPort": 5590,
"tcpSendBufferSize": 5,
"tcpReceiveBufferSize": 10,
"connectionTimeout": 1,
"tcpResponseTimeout": 5
},
{
"name": "Azure-Production",
"tcpServerHost": "XXX",
"tcpServerPort": 5590,
"tcpSendBufferSize": 5,
"tcpReceiveBufferSize": 5,
"connectionTimeout": 2,
"tcpResponseTimeout": 5
}
]
},
"webSocketProtocol": {
"defaultRemoteClient": "GCP-Production",
"remoteClients": [
{
"name": "GCP-Production",
"webSocketHostBaseUrl": "ws://XXX.XXX.XXX.XXX:5580",
"wsResponseTimeout": 5
},
{
"name": "Azure-Production",
"webSocketHostBaseUrl": "ws://XXX.XXX.XXX.XXX:5580",
"wsResponseTimeout": 5
}
]
}
}
Write your ClientProxy class and extends RemoteProxy class.<br/>
Add namespace using.
using ZayniFramework.Common;
using ZayniFramework.Middle.Service.Client;
/// <summary>Some client proxy.
/// </summary>
public class PaymentProxy : RemoteProxy
Write your constructor and pass the service client name to base class.
/// <summary>預設建構子
/// </summary>
public PaymentProxy() : base( "PaymentServiceProxy" )
{
// pass
}
/// <summary>多載建構子
/// </summary>
/// <param name="path">服務客戶端 serviceClientConfig.json 設定檔的路徑</param>
public PaymentProxy( string path = "./serviceClientConfig.json" ) : base( serviceClientName: "PaymentServiceProxy", configPath: "./serviceClientConfig.json" )
{
// pass
}
Then, you can use the RemoteProxy base methods, you can send a RPC request or publish message to your Middle.ServiceHost service action.
/// <summary>執行遠端服務動作的測試
/// </summary>
public new Result<TResDTO> Execute<TReqDTO, TResDTO>( string actionName, TReqDTO request ) => base.Execute<TReqDTO, TResDTO>( actionName, request );
/// <summary>發佈 ServiceEvent 服務事件訊息的測試
/// </summary>
public new Result Publish<TMsgDTO>( string actionName, TMsgDTO dto ) => base.Publish<TMsgDTO>( actionName, dto );
Finally, you can use your own Client Proxy object to send RPC request or publish message.
var paymentProxy = new PaymentProxy( "./serviceClientConfig.json" );
var reqDTO = new SomethingDTO()
{
SomeMessage = "This is a message from masOS or linux.",
SomeDate = DateTime.Now,
SomeMagicNumber = 24.52D,
LuckyNumber = 333,
IsSuperMan = true
};
// Send a RPC request to the ServiceHost server-side.
var r = paymentProxy.Execute<SomethingDTO, MagicDTO>( "MagicTestAction", reqDTO );
More detail sample code. You can go to Test/ServieHostTest/ServiceHost.Client.App directory to see the complete sample code.
Middleware ServiceHost.Client example.
You have define your own business logic service by using Middle.ServiceHost module. Now you can use Middle.ServiceHost.Client module to request your service action or trigger a service event to publish a message to your service action.
First, add a serviceClientConfig.json in your client-side app project.
{
"serviceClients": [
{
"serviceClientName": "PaymentServiceProxy",
"remoteServiceName": "PaymentService",
"remoteHostType": "TCPSocket",
"remoteClient": "GCP-Production",
"enableActionLogToDB": true
},
{
"serviceClientName": "OrderServiceProxy",
"remoteServiceName": "OrderService",
"remoteHostType": "RabbitMQ",
"remoteClient": "GCP-Production",
"enableActionLogToDB": true
}
],
"rabbitMQProtocol": {
"defaultRemoteClient": "GCP-Production",
"remoteClients": [
{
"name": "GCP-Production",
"mbHost": "XXX",
"mbPort": 5672,
"mbUserId": "XXX",
"mbPassword": "XXX",
"mbVHost": "SomeHost",
"defaultExchange": "Middle.Test.Topic",
"rpc": {
"exchange": "Middle.Test.Topic",
"routingKey": "RPC.Server.",
"rpcReplyQueue": "Middle.Server.RPC.Res",
"rcpResponseTimeout": 5
},
"publish": {
"exchange": "Middle.Test.Topic",
"routingKey": "Event.Client."
},
"listen": {
"msgQueue": "Middle.Client.ListenServer.Msg",
"msgRoutingKey": "Event.Server."
}
},
{
"name": "Azure-Production",
"mbHost": "XXX",
"mbPort": 5672,
"mbUserId": "XXX",
"mbPassword": "XXX",
"mbVHost": "SomeHost",
"defaultExchange": "Middle.Test.Topic",
"rpc": {
"exchange": "Middle.Test.Topic",
"routingKey": "RPC.Server.",
"rpcReplyQueue": "Middle.Server.RPC.Res",
"rcpResponseTimeout": 5
},
"publish": {
"exchange": "Middle.Test.Topic",
"routingKey": "Event.Client."
},
"listen": {
"msgQueue": "Middle.Client.ListenServer.Msg",
"msgRoutingKey": "Event.Server."
}
}
]
},
"tcpSocketProtocol": {
"defaultRemoteClient": "GCP-Production",
"remoteClients": [
{
"name": "GCP-Production",
"tcpServerHost": "XXX",
"tcpServerPort": 5590,
"tcpSendBufferSize": 5,
"tcpReceiveBufferSize": 10,
"connectionTimeout": 1,
"tcpResponseTimeout": 5
},
{
"name": "Azure-Production",
"tcpServerHost": "XXX",
"tcpServerPort": 5590,
"tcpSendBufferSize": 5,
"tcpReceiveBufferSize": 5,
"connectionTimeout": 2,
"tcpResponseTimeout": 5
}
]
},
"webSocketProtocol": {
"defaultRemoteClient": "GCP-Production",
"remoteClients": [
{
"name": "GCP-Production",
"webSocketHostBaseUrl": "ws://XXX.XXX.XXX.XXX:5580",
"wsResponseTimeout": 5
},
{
"name": "Azure-Production",
"webSocketHostBaseUrl": "ws://XXX.XXX.XXX.XXX:5580",
"wsResponseTimeout": 5
}
]
}
}
Write your ClientProxy class and extends RemoteProxy class.<br/>
Add namespace using.
using ZayniFramework.Common;
using ZayniFramework.Middle.Service.Client;
/// <summary>Some client proxy.
/// </summary>
public class PaymentProxy : RemoteProxy
Write your constructor and pass the service client name to base class.
/// <summary>預設建構子
/// </summary>
public PaymentProxy() : base( "PaymentServiceProxy" )
{
// pass
}
/// <summary>多載建構子
/// </summary>
/// <param name="path">服務客戶端 serviceClientConfig.json 設定檔的路徑</param>
public PaymentProxy( string path = "./serviceClientConfig.json" ) : base( serviceClientName: "PaymentServiceProxy", configPath: "./serviceClientConfig.json" )
{
// pass
}
Then, you can use the RemoteProxy base methods, you can send a RPC request or publish message to your Middle.ServiceHost service action.
/// <summary>執行遠端服務動作的測試
/// </summary>
public new Result<TResDTO> Execute<TReqDTO, TResDTO>( string actionName, TReqDTO request ) => base.Execute<TReqDTO, TResDTO>( actionName, request );
/// <summary>發佈 ServiceEvent 服務事件訊息的測試
/// </summary>
public new Result Publish<TMsgDTO>( string actionName, TMsgDTO dto ) => base.Publish<TMsgDTO>( actionName, dto );
Finally, you can use your own Client Proxy object to send RPC request or publish message.
var paymentProxy = new PaymentProxy( "./serviceClientConfig.json" );
var reqDTO = new SomethingDTO()
{
SomeMessage = "This is a message from masOS or linux.",
SomeDate = DateTime.Now,
SomeMagicNumber = 24.52D,
LuckyNumber = 333,
IsSuperMan = true
};
// Send a RPC request to the ServiceHost server-side.
var r = paymentProxy.Execute<SomethingDTO, MagicDTO>( "MagicTestAction", reqDTO );
More detail sample code. You can go to Test/ServieHostTest/ServiceHost.Client.App directory to see the complete sample code.
Dependencies
-
.NETStandard 2.0
- Newtonsoft.Json (>= 11.0.2)
- RabbitMQ.Client (>= 5.1.0)
- RestSharp (>= 106.3.1)
- websocketsharp.core (>= 1.0.0)
- ZayniFramework.Common (>= 2.0.1)
- ZayniFramework.DataAccess (>= 2.0.1)
- ZayniFramework.Logging (>= 2.0.1)
- ZayniFramework.Middle.Service.Entity (>= 2.0.1)
- ZayniFramework.RabbitMQ.Msg.Client (>= 1.0.1)
- ZayniFramework.Serialization (>= 2.0.1)
- ZayniFramework.Validation (>= 2.0.1)
- ZeroFormatter (>= 1.6.4)
Used By
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ZayniFramework.Middle.Service.Client:
Package | Downloads |
---|---|
ZayniFramework.Caching
This is a cache management for .NET application. You can store you data in in-process memory, Redis server, MySQL memory table engine or Zayni Framework's build-in Remote.ShareData.Service.
|
|
ZayniFramework.Middle.Service.Grpc.Client
This is an extension module for Zayni Framework's Middle.Service.Client module. This extension module provide the gRPC RemoteClient implementation for Middle.Service.Client module.
|
|
ZayniFramework.Middle.Service.HttpCore.Client
This is an extension module for Zayni Framework's Middle.Service.Client module. This extension module provide the Http RemoteClient implementation for Middle.Service.Client module.
|
GitHub repositories
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated |
---|---|---|
2.31.120 | 81 | 3/14/2021 |
2.30.115 | 276 | 3/6/2021 |
2.30.114 | 39 | 3/6/2021 |
2.20.101 | 120 | 3/1/2021 |
2.19.3 | 97 | 2/11/2021 |
2.19.2 | 1,627 | 2/6/2021 |
2.19.1 | 142 | 1/6/2021 |
2.19.0 | 162 | 1/1/2021 |
2.18.3 | 155 | 12/27/2020 |
2.18.2 | 894 | 8/29/2020 |
2.18.1 | 4,095 | 8/26/2020 |
2.18.0 | 458 | 8/20/2020 |
2.17.135 | 129 | 8/19/2020 |
2.17.134 | 191 | 7/28/2020 |
2.17.133 | 205 | 7/27/2020 |
2.17.132 | 221 | 7/18/2020 |
2.17.131 | 392 | 7/11/2020 |
2.16.130 | 342 | 6/13/2020 |
2.15.128 | 237 | 6/3/2020 |
2.15.127 | 304 | 5/31/2020 |
2.15.126 | 1,026 | 4/30/2020 |
2.14.122 | 244 | 4/13/2020 |
2.13.100 | 314 | 3/12/2020 |
2.12.51 | 342 | 2/18/2020 |
2.11.50 | 268 | 2/10/2020 |
2.10.44 | 364 | 1/30/2020 |
2.9.43 | 544 | 1/11/2020 |
2.8.42 | 343 | 1/10/2020 |
2.8.41 | 327 | 1/5/2020 |
2.7.40 | 361 | 1/2/2020 |
2.7.39 | 284 | 1/2/2020 |
2.7.38 | 412 | 1/1/2020 |
2.6.37 | 314 | 12/23/2019 |
2.6.35 | 549 | 12/4/2019 |
2.6.1 | 275 | 12/2/2019 |
2.6.0 | 283 | 11/28/2019 |
2.5.2 | 436 | 11/26/2019 |
2.5.1 | 372 | 11/12/2019 |
2.5.0 | 268 | 11/9/2019 |
2.4.3 | 420 | 10/16/2019 |
2.4.2 | 256 | 10/16/2019 |
2.4.1 | 342 | 9/20/2019 |
2.3.113 | 40 | 3/6/2021 |
2.3.112 | 46 | 3/6/2021 |
2.3.28 | 322 | 9/19/2019 |
2.3.27 | 426 | 8/30/2019 |
2.3.26 | 406 | 8/20/2019 |
2.3.25 | 353 | 8/12/2019 |
2.3.22 | 283 | 7/31/2019 |
2.3.21 | 454 | 7/20/2019 |
2.3.20 | 397 | 6/22/2019 |
2.3.19 | 336 | 6/14/2019 |
2.3.18 | 329 | 6/13/2019 |
2.3.17 | 322 | 6/13/2019 |
2.3.15 | 369 | 6/8/2019 |
2.3.14 | 336 | 6/8/2019 |
2.3.13 | 348 | 5/30/2019 |
2.3.12 | 347 | 5/24/2019 |
2.3.11 | 316 | 5/24/2019 |
2.3.10 | 363 | 5/21/2019 |
2.3.9 | 358 | 5/9/2019 |
2.3.8 | 374 | 5/8/2019 |
2.3.7 | 375 | 4/30/2019 |
2.3.6 | 458 | 4/23/2019 |
2.3.5 | 381 | 4/19/2019 |
2.3.4 | 354 | 4/18/2019 |
2.3.3 | 357 | 4/17/2019 |
2.3.2 | 370 | 4/6/2019 |
2.3.1 | 428 | 12/15/2018 |
2.3.0 | 518 | 12/7/2018 |
2.2.7 | 379 | 11/30/2018 |
2.2.6 | 449 | 11/25/2018 |
2.2.5 | 382 | 11/23/2018 |
2.2.4 | 386 | 11/22/2018 |
2.2.3 | 373 | 11/21/2018 |
2.2.2 | 397 | 11/19/2018 |
2.2.1 | 436 | 11/17/2018 |
2.2.0 | 410 | 11/16/2018 |
2.1.0 | 440 | 11/15/2018 |
2.0.1 | 420 | 11/6/2018 |
2.0.0 | 456 | 11/4/2018 |