예제 #1
0
        /// <inheritdoc/>
        /// <exception cref="ArgumentNullException"></exception>
        public Task PublishAsync(ManagedMqttApplicationMessage applicationMessage)
        {
            if (applicationMessage is null)
            {
                throw new ArgumentNullException(nameof(applicationMessage));
            }

            return(InternalClient.PublishAsync(applicationMessage));
        }
예제 #2
0
        /// <inheritdoc/>
        /// <exception cref="ArgumentNullException"></exception>
        public Task <MqttClientPublishResult> PublishAsync(MqttApplicationMessage applicationMessage, CancellationToken cancellationToken)
        {
            if (applicationMessage is null)
            {
                throw new ArgumentNullException(nameof(applicationMessage));
            }

            return(InternalClient.PublishAsync(applicationMessage, cancellationToken));
        }
예제 #3
0
        public async Task PublishMessage <T>(T messagePayload, string topic) where T : class
        {
            var appMessage = new MqttApplicationMessageBuilder()
                             .WithContentType(typeof(T).Name)
                             .WithPayload(JsonConvert.SerializeObject(messagePayload))
                             .WithTopic(topic)
                             .Build();

            await InternalClient.PublishAsync(appMessage, CancellationToken.None);
        }