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.
 
 
 
 

25 lines
860 B

  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. }