mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
25 lines
860 B
C#
25 lines
860 B
C#
using System;
|
|
|
|
namespace MQTTnet.Extensions.Rpc.Options.TopicGeneration
|
|
{
|
|
public sealed class DefaultMqttRpcClientTopicGenerationStrategy : IMqttRpcClientTopicGenerationStrategy
|
|
{
|
|
public MqttRpcTopicPair CreateRpcTopics(TopicGenerationContext context)
|
|
{
|
|
if (context.MethodName.Contains("/") || context.MethodName.Contains("+") || context.MethodName.Contains("#"))
|
|
{
|
|
throw new ArgumentException("The method name cannot contain /, + or #.");
|
|
}
|
|
|
|
var requestTopic = $"MQTTnet.RPC/{Guid.NewGuid():N}/{context.MethodName}";
|
|
var responseTopic = requestTopic + "/response";
|
|
|
|
return new MqttRpcTopicPair
|
|
{
|
|
RequestTopic = requestTopic,
|
|
ResponseTopic = responseTopic
|
|
};
|
|
}
|
|
}
|
|
}
|