mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-23 03:50:30 +08:00
调整MqttRpc提示
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
|
||||
#endregion
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -116,6 +118,7 @@ public class OperResult : IOperResult
|
||||
/// <summary>
|
||||
/// 异常堆栈
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Exception? Exception;
|
||||
|
||||
/// <summary>
|
||||
|
@@ -157,7 +157,8 @@ public partial class MqttClient : BusinessBaseWithCacheIntervalScript<VariableDa
|
||||
|
||||
if (!_driverPropertys.DeviceRpcEnable || string.IsNullOrEmpty(args.ClientId))
|
||||
return;
|
||||
if (args.ApplicationMessage.Topic != _driverPropertys.RpcWriteTopic)
|
||||
var t = string.Format(TgMqttRpcClientTopicGenerationStrategy.RpcTopic, _driverPropertys.RpcWriteTopic);
|
||||
if (MqttTopicFilterComparer.Compare(args.ApplicationMessage.Topic, t) != MqttTopicFilterCompareResult.IsMatch)
|
||||
return;
|
||||
var rpcDatas = Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment).FromJsonString<Dictionary<string, string>>();
|
||||
if (rpcDatas == null)
|
||||
@@ -169,7 +170,7 @@ public partial class MqttClient : BusinessBaseWithCacheIntervalScript<VariableDa
|
||||
if (isConnect.IsSuccess)
|
||||
{
|
||||
var variableMessage = new MqttApplicationMessageBuilder()
|
||||
.WithTopic($"{args.ApplicationMessage.Topic}/response")
|
||||
.WithTopic($"{args.ApplicationMessage.Topic}/Response")
|
||||
.WithPayload(mqttRpcResult.ToJsonString(true)).Build();
|
||||
await _mqttClient.PublishAsync(variableMessage);
|
||||
}
|
||||
@@ -190,7 +191,7 @@ public partial class MqttClient : BusinessBaseWithCacheIntervalScript<VariableDa
|
||||
if (tag != null)
|
||||
{
|
||||
var rpcEnable = tag.GetPropertyValue(DeviceId, nameof(_variablePropertys.VariableRpcEnable))?.Value?.ToBoolean();
|
||||
if (rpcEnable != true)
|
||||
if (rpcEnable == false)
|
||||
{
|
||||
mqttRpcResult.Add(rpcData.Key, new("权限不足,变量不支持写入"));
|
||||
}
|
||||
|
@@ -80,7 +80,7 @@ public class MqttClientProperty : BusinessPropertyWithCacheIntervalScript
|
||||
/// <summary>
|
||||
/// Rpc写入Topic
|
||||
/// </summary>
|
||||
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway/+/[RpcWrite]} ,其中RpcWrite为该属性填入内容,+通配符是不固定GUID值,每次执行写入时会在不同的主题中返回;返回结果主题会在主题后添加Response , 也就是{ThingsGateway/+/[RpcWrite]/Response}")]
|
||||
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway.Rpc/+/[RpcWrite]} ,其中RpcWrite为该属性填入内容,+通配符是不固定GUID值,每次执行写入时会在不同的主题中返回;返回结果主题会在主题后添加Response , 也就是{ThingsGateway.Rpc/+/[RpcWrite]/Response}")]
|
||||
public string RpcWriteTopic
|
||||
{
|
||||
get
|
||||
|
@@ -121,7 +121,8 @@ public partial class MqttServer : BusinessBaseWithCacheIntervalScript<VariableDa
|
||||
{
|
||||
if (!_driverPropertys.DeviceRpcEnable || string.IsNullOrEmpty(args.ClientId))
|
||||
return;
|
||||
if (args.ApplicationMessage.Topic != _driverPropertys.RpcWriteTopic)
|
||||
var t = string.Format(TgMqttRpcClientTopicGenerationStrategy.RpcTopic, _driverPropertys.RpcWriteTopic);
|
||||
if (MqttTopicFilterComparer.Compare(args.ApplicationMessage.Topic, t) != MqttTopicFilterCompareResult.IsMatch)
|
||||
return;
|
||||
var rpcDatas = Encoding.UTF8.GetString(args.ApplicationMessage.PayloadSegment).FromJsonString<Dictionary<string, string>>();
|
||||
if (rpcDatas == null)
|
||||
@@ -131,7 +132,7 @@ public partial class MqttServer : BusinessBaseWithCacheIntervalScript<VariableDa
|
||||
try
|
||||
{
|
||||
var variableMessage = new MqttApplicationMessageBuilder()
|
||||
.WithTopic($"{args.ApplicationMessage.Topic}/response")
|
||||
.WithTopic($"{args.ApplicationMessage.Topic}/Response")
|
||||
.WithPayload(mqttRpcResult.ToJsonString(true)).Build();
|
||||
await _mqttServer.InjectApplicationMessage(
|
||||
new InjectedMqttApplicationMessage(variableMessage));
|
||||
@@ -152,7 +153,7 @@ public partial class MqttServer : BusinessBaseWithCacheIntervalScript<VariableDa
|
||||
if (tag != null)
|
||||
{
|
||||
var rpcEnable = tag.GetPropertyValue(DeviceId, nameof(_variablePropertys.VariableRpcEnable))?.Value?.ToBoolean();
|
||||
if (rpcEnable != true)
|
||||
if (rpcEnable == false)
|
||||
{
|
||||
mqttRpcResult.Add(rpcData.Key, new("权限不足,变量不支持写入"));
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ public class MqttServerProperty : BusinessPropertyWithCacheIntervalScript
|
||||
/// <summary>
|
||||
/// Rpc写入Topic
|
||||
/// </summary>
|
||||
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway/+/[RpcWrite]} ,其中RpcWrite为该属性填入内容,+通配符是不固定GUID值,每次执行写入时会在不同的主题中返回;返回结果主题会在主题后添加Response , 也就是{ThingsGateway/+/[RpcWrite]/Response}")]
|
||||
[DynamicProperty("Rpc写入Topic", "实际的写入主题为固定通配 {ThingsGateway.Rpc/+/[RpcWrite]} ,其中RpcWrite为该属性填入内容,+通配符是不固定GUID值,每次执行写入时会在不同的主题中返回;返回结果主题会在主题后添加Response , 也就是{ThingsGateway.Rpc/+/[RpcWrite]/Response}")]
|
||||
public string RpcWriteTopic
|
||||
{
|
||||
get
|
||||
|
Reference in New Issue
Block a user