You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultMqttRpcClientTopicGenerationStrategy.cs 860 B

преди 4 години
преди 4 години
123456789101112131415161718192021222324
  1. using System;
  2. namespace MQTTnet.Extensions.Rpc.Options.TopicGeneration
  3. {
  4. public sealed class DefaultMqttRpcClientTopicGenerationStrategy : IMqttRpcClientTopicGenerationStrategy
  5. {
  6. public MqttRpcTopicPair CreateRpcTopics(TopicGenerationContext context)
  7. {
  8. if (context.MethodName.Contains("/") || context.MethodName.Contains("+") || context.MethodName.Contains("#"))
  9. {
  10. throw new ArgumentException("The method name cannot contain /, + or #.");
  11. }
  12. var requestTopic = $"MQTTnet.RPC/{Guid.NewGuid():N}/{context.MethodName}";
  13. var responseTopic = requestTopic + "/response";
  14. return new MqttRpcTopicPair
  15. {
  16. RequestTopic = requestTopic,
  17. ResponseTopic = responseTopic
  18. };
  19. }
  20. }
  21. }