Skip to content

Commit

Permalink
ClientBase工作于RPC模式时,支持下行通知
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Jun 26, 2024
1 parent 6bc0062 commit 78e1e9d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion NewLife.Remoting/Clients/ClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,23 @@ protected virtual void OnInit()
/// <summary>创建RPC客户端</summary>
/// <param name="urls"></param>
/// <returns></returns>
protected virtual ApiClient CreateRpc(String urls) => new MyApiClient { Client = this, Servers = urls.Split(","), Log = Log };
protected virtual ApiClient CreateRpc(String urls)
{
var client = new MyApiClient { Client = this, Servers = urls.Split(","), Log = Log };
client.Received += (s, e) =>
{
var msg = e.Message;
var api = e.ApiMessage;
if (msg != null && !msg.Reply && api != null && api.Action == "Notify")
{
var cmd = api.Data?.ToStr().ToJsonEntity<CommandModel>();
if (cmd != null)
_ = ReceiveCommand(cmd, client.Local?.Type + "");
}
};

return client;
}

class MyApiClient : ApiClient
{
Expand Down

0 comments on commit 78e1e9d

Please sign in to comment.