public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, object data, MqttQualityOfServiceLevel qualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce) { try { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } if (data == null) { throw new ArgumentNullException(nameof(data)); } string value = JsonConvert.SerializeObject(data, new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(), DateFormatString = "yyyy-MM-dd HH:mm:ss" }); return(publisher.PublishAsync(new[] { new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(value).WithQualityOfServiceLevel(qualityOfServiceLevel).Build() })); } catch (Exception ex) { return(null); } }
public MqttPublisher(IApplicationMessagePublisher client, MqttPublishSettings settings, Action <Inverter, Measurement, Exception>?publishFailed = null) { _client = client; _settings = settings; _publishFailed = publishFailed; }
public static Task <MqttClientPublishResult> PublishAsync(this IApplicationMessagePublisher publisher, Func <MqttApplicationMessageBuilder, MqttApplicationMessageBuilder> builder) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } var message = builder(new MqttApplicationMessageBuilder()).Build(); return(publisher.PublishAsync(message, CancellationToken.None)); }
public static Task <MqttClientPublishResult> PublishEventAsync( this IApplicationMessagePublisher applicationMessagePublisher, EventBase @event, CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { return(Task.FromCanceled <MqttClientPublishResult>(cancellationToken)); } return(applicationMessagePublisher.PublishAsync(@event.BuildMqttMessage(), cancellationToken)); }
public static MqttClientPublishResult PublishEvent( this IApplicationMessagePublisher applicationMessagePublisher, EventBase @event, CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(cancellationToken); } return(applicationMessagePublisher.PublishAsync(@event.BuildMqttMessage(), cancellationToken).GetAwaiter().GetResult()); }
public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } return(publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).Build())); }
public static Task PublishAsync(this IApplicationMessagePublisher client, params MqttApplicationMessage[] applicationMessages) { if (client == null) { throw new ArgumentNullException(nameof(client)); } if (applicationMessages == null) { throw new ArgumentNullException(nameof(applicationMessages)); } return(client.PublishAsync(applicationMessages)); }
public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload, MqttQualityOfServiceLevel qualityOfServiceLevel) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } return(publisher.PublishAsync(new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(payload).WithQualityOfServiceLevel(qualityOfServiceLevel).Build())); }
public static Task <MqttClientPublishResult> PublishAsync(this IApplicationMessagePublisher publisher, MqttApplicationMessage applicationMessage) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (applicationMessage == null) { throw new ArgumentNullException(nameof(applicationMessage)); } return(publisher.PublishAsync(applicationMessage, CancellationToken.None)); }
public static Task <MqttClientPublishResult> PublishAsync(this IApplicationMessagePublisher publisher, string topic) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } return(publisher.PublishAsync(builder => builder .WithTopic(topic))); }
public static Task PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } return(publisher.PublishAsync(builder => builder .WithTopic(topic) .WithPayload(payload))); }
public static async Task PublishAsync(this IApplicationMessagePublisher publisher, IEnumerable <MqttApplicationMessage> applicationMessages) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (applicationMessages == null) { throw new ArgumentNullException(nameof(applicationMessages)); } foreach (var applicationMessage in applicationMessages) { await publisher.PublishAsync(applicationMessage).ConfigureAwait(false); } }
public static async Task PublishAsync(this IApplicationMessagePublisher publisher, params MqttApplicationMessage[] applicationMessages) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (applicationMessages == null) { throw new ArgumentNullException(nameof(applicationMessages)); } foreach (var applicationMessage in applicationMessages) { await publisher.PublishAsync(applicationMessage, CancellationToken.None).ConfigureAwait(false); } }
public static Task <MqttClientPublishResult> PublishAsync(this IApplicationMessagePublisher publisher, string topic, string payload, MqttQualityOfServiceLevel qualityOfServiceLevel, bool retain) { if (publisher == null) { throw new ArgumentNullException(nameof(publisher)); } if (topic == null) { throw new ArgumentNullException(nameof(topic)); } return(publisher.PublishAsync(builder => builder .WithTopic(topic) .WithPayload(payload) .WithQualityOfServiceLevel(qualityOfServiceLevel) .WithRetainFlag(retain))); }
public ProcessingCommandHandler( IProcessingCommandHandlerContextFactory contextFactory, IEventCommitter eventCommitter, IEventStore eventStore, IEventPublisher eventPublisher, IApplicationMessagePublisher applicationMessagePublisher, IStringObjectSerializer objectSerializer, IServiceProvider serviceProvider, ILogger <ProcessingCommandHandler> logger) { this.contextFactory = contextFactory; this.eventCommitter = eventCommitter; this.eventStore = eventStore; this.eventPublisher = eventPublisher; this.applicationMessagePublisher = applicationMessagePublisher; this.objectSerializer = objectSerializer; this.serviceProvider = serviceProvider; this.logger = logger; handlerMapping = new ConcurrentDictionary <Type, ICommandHandler>(); asyncHandlerMapping = new ConcurrentDictionary <Type, ICommandAsyncHandler>(); }
public static Task PublishAsync(this IApplicationMessagePublisher publisher, Func <MqttApplicationMessageBuilder, MqttApplicationMessageBuilder> builder) { var message = builder(new MqttApplicationMessageBuilder()).Build(); return(publisher.PublishAsync(message)); }
public Publisher(IApplicationMessagePublisher mqttPublisher) { this.mqttPublisher = mqttPublisher; this.cancellationTokenSource = new CancellationTokenSource(); }