Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8627ae61fa | ||
|
|
02523028db |
@@ -42,6 +42,9 @@ public partial class Synapse
|
|||||||
|
|
||||||
private string? FireRpc(string app, string action, object? param, Dictionary<string, string>? headers = null,
|
private string? FireRpc(string app, string action, object? param, Dictionary<string, string>? headers = null,
|
||||||
int? timeout = null)
|
int? timeout = null)
|
||||||
|
{
|
||||||
|
// 检查并发情况下的线程安全问题,使用锁保证字典操作的原子性
|
||||||
|
lock (ResponseCompletionSources)
|
||||||
{
|
{
|
||||||
string paramJson;
|
string paramJson;
|
||||||
if (param is string strParam)
|
if (param is string strParam)
|
||||||
@@ -100,3 +103,4 @@ public partial class Synapse
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -20,9 +20,9 @@ public partial class Synapse
|
|||||||
|
|
||||||
private void RunRpcServer()
|
private void RunRpcServer()
|
||||||
{
|
{
|
||||||
Client!.ApplicationMessageReceivedAsync += e =>
|
Client!.ApplicationMessageReceivedAsync += async e =>
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
if (!e.ApplicationMessage.Topic.StartsWith(RpcServerTopicPrefix)) return;
|
if (!e.ApplicationMessage.Topic.StartsWith(RpcServerTopicPrefix)) return;
|
||||||
var reqBody = e.ApplicationMessage.ConvertPayloadToString();
|
var reqBody = e.ApplicationMessage.ConvertPayloadToString();
|
||||||
@@ -109,7 +109,6 @@ public partial class Synapse
|
|||||||
"Synapse Rpc Server Return: ({BasicPropertiesMessageId}) {BasicPropertiesType}@{OptionsAppName} -> {BasicPropertiesReplyTo}\n{ReturnJson}",
|
"Synapse Rpc Server Return: ({BasicPropertiesMessageId}) {BasicPropertiesType}@{OptionsAppName} -> {BasicPropertiesReplyTo}\n{ReturnJson}",
|
||||||
appInfo[2], action, Options.AppName, appInfo[0], returnJson);
|
appInfo[2], action, Options.AppName, appInfo[0], returnJson);
|
||||||
});
|
});
|
||||||
return Task.CompletedTask;
|
|
||||||
};
|
};
|
||||||
SubRpcServerTopic();
|
SubRpcServerTopic();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user