示例#1
0
        /// <summary>
        /// MQTT subscribe to a topic.  Remember, these subscriptions are ephemeral.
        /// </summary>
        /// <param name="subscriptions"></param>
        /// <returns></returns>
        public async Task SubscribeAsync(Tuple <string, QualityOfServiceLevelType, Action <string, string, byte[]> >[] subscriptions)
        {
            try
            {
                Dictionary <string, QualityOfServiceLevelType> dict = new Dictionary <string, QualityOfServiceLevelType>();

                foreach (var tuple in subscriptions)
                {
                    dict.Add(tuple.Item1, tuple.Item2);
                    dispatcher.Register(tuple.Item1, tuple.Item3);
                }

                SubscribeMessage msg = new SubscribeMessage(session.NewId(), dict);

                //if (channel.RequireBlocking)
                //{
                //    channel.SendAsync(msg.Encode()).GetAwaiter();
                //    //Task t = channel.SendAsync(msg.Encode());
                //    //Task.WaitAll(t);
                //}
                //else
                //{
                await channel.SendAsync(msg.Encode());

                //}
            }
            catch (Exception ex)
            {
                OnChannelError?.Invoke(this, new ChannelErrorEventArgs(channel.Id, ex));
            }
        }
示例#2
0
        /// <summary>
        /// MQTT subscribe to a topic.  Remember, these subscriptionns are ephemeral.
        /// </summary>
        /// <param name="topicUriString"></param>
        /// <param name="qos"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public async Task SubscribeAsync(string topicUriString, QualityOfServiceLevelType qos, Action <string, string, byte[]> action)
        {
            try
            {
                Dictionary <string, QualityOfServiceLevelType> dict = new Dictionary <string, QualityOfServiceLevelType>();
                dict.Add(topicUriString, qos);
                dispatcher.Register(topicUriString, action);
                SubscribeMessage msg = new SubscribeMessage(session.NewId(), dict);


                //if (channel.RequireBlocking)
                //{
                //    channel.SendAsync(msg.Encode()).GetAwaiter();
                //    //Task t = channel.SendAsync(msg.Encode());
                //    //Task.WaitAll(t);
                //}
                //else
                //{
                await channel.SendAsync(msg.Encode());

                //}
            }
            catch (Exception ex)
            {
                OnChannelError?.Invoke(this, new ChannelErrorEventArgs(channel.Id, ex));
            }
        }
示例#3
0
        public async Task SubscribeAsync(string topic, QualityOfServiceLevelType qos, Action <string, string, byte[]> action)
        {
            Dictionary <string, QualityOfServiceLevelType> dict = new Dictionary <string, QualityOfServiceLevelType>();

            dict.Add(topic, qos);
            dispatcher.Register(topic, action);
            SubscribeMessage msg = new SubscribeMessage(session.NewId(), dict);
            await channel.SendAsync(msg.Encode());
        }
示例#4
0
        public async Task SubscribeAsync(Tuple <string, QualityOfServiceLevelType, Action <string, string, byte[]> >[] subscriptions)
        {
            Dictionary <string, QualityOfServiceLevelType> dict = new Dictionary <string, QualityOfServiceLevelType>();

            foreach (var tuple in subscriptions)
            {
                dict.Add(tuple.Item1, tuple.Item2);
                dispatcher.Register(tuple.Item1, tuple.Item3);
            }

            SubscribeMessage msg = new SubscribeMessage(session.NewId(), dict);
            await channel.SendAsync(msg.Encode());
        }
示例#5
0
 /// <summary>
 /// MQTT subscribe to a topic.  Remember, these subscriptionns are ephemeral.
 /// </summary>
 /// <param name="topicUriString"></param>
 /// <param name="qos"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 public async Task SubscribeAsync(string topicUriString, QualityOfServiceLevelType qos, Action <string, string, byte[]> action)
 {
     try
     {
         Dictionary <string, QualityOfServiceLevelType> dict = new Dictionary <string, QualityOfServiceLevelType>();
         dict.Add(topicUriString.ToLowerInvariant(), qos);
         dispatcher.Register(topicUriString.ToLowerInvariant(), action);
         SubscribeMessage msg = new SubscribeMessage(session.NewId(), dict);
         await channel.SendAsync(msg.Encode());
     }
     catch (Exception ex)
     {
         OnChannelError?.Invoke(this, new ChannelErrorEventArgs(channel.Id, ex));
     }
 }
示例#6
0
        public async Task SubscribeAsync(
            Tuple <string, QualityOfServiceLevelType, Action <string, string, byte[]> >[] subscriptions)
        {
            try
            {
                Dictionary <string, QualityOfServiceLevelType>
                dict = new Dictionary <string, QualityOfServiceLevelType>();

                foreach (var tuple in subscriptions)
                {
                    dict.Add(tuple.Item1, tuple.Item2);
                    dispatcher.Register(tuple.Item1, tuple.Item3);
                }

                SubscribeMessage msg = new SubscribeMessage(session.NewId(), dict);

                await Channel.SendAsync(msg.Encode());
            }
            catch (Exception ex)
            {
                OnChannelError?.Invoke(this, new ChannelErrorEventArgs(Channel.Id, ex));
            }
        }