Пример #1
0
 public Publish(ushort packetId, string topic, ReadOnlyMemory <byte> message, QosLevel qos)
 {
     Id      = packetId;
     Topic   = topic ?? throw new ArgumentNullException(nameof(topic));
     Message = message;
     Qos     = qos;
 }
Пример #2
0
        public IMessengerListener GetListener(string topic = "", QosLevel qosLevel = QosLevel.AtLeastOnce)
        {
            var listener = Factory.CreateMessengerListener(Client);

            listener.Topic    = topic;
            listener.QosLevel = qosLevel;
            return(listener);
        }
Пример #3
0
        public IMessengerPublisher GetPublisher(string topic = "", QosLevel qosLevel = QosLevel.AtLeastOnce)
        {
            var messenger = Factory.CreateMessengerPublisher(Client, ApiId);

            messenger.Topic    = topic;
            messenger.QosLevel = qosLevel;
            return(messenger);
        }
Пример #4
0
        public void Messenger_GetListener_ValuesCorrect()
        {
            const string   TOPIC     = "TESTTOPIC";
            const QosLevel QOS_LEVEL = QosLevel.AtLeastOnce;

            using (var listener = messenger.GetListener(TOPIC, QOS_LEVEL))
            {
                moqFactory.Verify(x => x.CreateMessengerListener(moqFactory.Client.Object));
                Assert.AreEqual(moqFactory.Listener.Object, listener);
                moqFactory.Listener.VerifySet(x => x.QosLevel = QOS_LEVEL);
                moqFactory.Listener.VerifySet(x => x.Topic    = TOPIC);
            }
        }
Пример #5
0
        public void MessengerListener_SubscribeUnsubscribe()
        {
            const QosLevel QOS   = QosLevel.ExactlyOnce;
            const string   TOPIC = "Test/+/blah";

            Listener.Topic    = TOPIC;
            Listener.QosLevel = QOS;

            moqFactory.Client.Verify(x => x.Subscribe(new[] { TOPIC }, new byte[] { (byte)QOS }));

            Listener.Topic = "";
            moqFactory.Client.Verify(x => x.Unsubscribe(new[] { TOPIC }));
        }
        public void MessengerPublisher_Publish_FlagsTest(QosLevel qosLevel, bool retain, string topic)
        {
            const string MSG = "Bogus Sugob";

            byte[] MSG_bytes = Encoding.UTF8.GetBytes(MSG);

            pub.QosLevel = qosLevel;
            pub.Retain   = retain;
            pub.Topic    = topic;

            pub.Publish(MSG);

            // Publish is done asynchronously with a task, wait to make sure it completes
            System.Threading.Thread.Sleep(20);

            moqFactory.Client.Verify(x => x.Publish(topic, It.IsAny <byte[]>(), (byte)qosLevel, retain));
        }
Пример #7
0
        /// <summary>
        /// Adds the options to the list.
        /// </summary>
        public void AddToOptionList(OptionList options, bool clearList = true)
        {
            if (clearList)
            {
                options.Clear();
            }

            options["RootTopic"]      = RootTopic;
            options["UndefinedValue"] = UndefinedValue;
            options["PublishFormat"]  = PublishFormat;
            options["QosLevel"]       = QosLevel.ToString();
            options["Retain"]         = Retain.ToString();
            options["MaxQueueSize"]   = MaxQueueSize.ToString();
            options["DataLifetime"]   = DataLifetime.ToString();
            options["DetailedLog"]    = DetailedLog.ToString();
            options["DeviceFilter"]   = DeviceFilter.ToRangeString();
        }
Пример #8
0
 public SubscriptionRequest(string topicName, QosLevel qos)
 {
     TopicName = topicName ?? throw new ArgumentNullException(nameof(topicName));
     Qos       = qos;
 }
Пример #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="clientId">Client identifier</param>
 /// <param name="username">Username</param>
 /// <param name="password">Password</param>
 /// <param name="willRetain">Will retain flag</param>
 /// <param name="willQosLevel">Will QOS level</param>
 /// <param name="willFlag">Will flag</param>
 /// <param name="willTopic">Will topic</param>
 /// <param name="willMessage">Will message</param>
 /// <param name="cleanSession">Clean sessione flag</param>
 /// <param name="keepAlivePeriod">Keep alive period</param>
 /// <param name="protocolVersion">Protocol version</param>
 public MqttConnectMessage(string clientId, string username, string password, bool willRetain, QosLevel willQosLevel, bool willFlag, string willTopic, string willMessage, bool cleanSession, ushort keepAlivePeriod, byte protocolVersion)
     : this(clientId, username, password, willRetain, (byte)willQosLevel, willFlag, willTopic, willMessage, cleanSession, keepAlivePeriod, protocolVersion)
 {
 }
Пример #10
0
 public PublishRequest(string topicName, ReadOnlyMemory <byte> message, QosLevel qos = QosLevel.Qos0)
 {
     TopicName = topicName ?? throw new ArgumentNullException(nameof(topicName));
     Message   = message;
     Qos       = qos;
 }