Exemple #1
0
        /// <summary>
        /// 发送消息到远程端并等待返回
        /// </summary>
        /// <param name="topic">主题</param>
        /// <param name="api">api</param>
        /// <param name="body">内容</param>
        /// <exception cref="TimeoutException"></exception>
        /// <returns></returns>
        public static async Task <Message> SendAsync(SingleTopic topic, Api api, ITimeoutRequest body)
        {
            var message    = EmqttdClient.GenerateMessage(api, body, Mode.Send);
            var key        = message.GetUniqueKey(topic.UniqueId);
            var timeout    = TimeSpan.FromSeconds(body.Timeout);
            var taskSetter = taskTable.Create <Message>(key, timeout);

            await EmqttdClient.PublishAsync(topic, message);

            return(await taskSetter.GetTask());
        }
Exemple #2
0
 /// <summary>
 /// 回复消息到远程端
 /// </summary>
 /// <param name="topic">主题</param>
 /// <param name="api">api</param>
 /// <param name="body">内容</param>
 /// <returns></returns>
 public static async Task ReturnAsync(SingleTopic topic, Api api, object body)
 {
     var message = GenerateMessage(api, body, Mode.Return);
     await EmqttdClient.PublishAsync(topic, message);
 }