/// <summary> /// Subscribe for notification events. /// </summary> /// <param name="notificationDelegate">The delegate that handlers subscription.</param> /// <returns>The <see cref="IEventBusSubscription"/> /// with <see cref="IDisposable"/> that can be used to remove the subscription.</returns> public IEventBusSubscription SubscribeSync(SubscriptionDelegate <TNotification> notificationDelegate) { EventBusSubscriberProvider eventBusSubscriberProvider = new EventBusSubscriberProvider(_configutationRabbitMQ, _connectionFactory, notificationDelegate); eventBusSubscriberProvider.TryToConnect(); return(eventBusSubscriberProvider); }
public EventBusSubscriberProvider(EventBusConfigutation configutationRabbitMQ, RabbitMQConnectionFactory connectionFactory, SubscriptionDelegate <TNotification> notificationDelegate) { _configutationRabbitMQ = configutationRabbitMQ; _connectionFactory = connectionFactory; _notificationDelegate = notificationDelegate; _policy = RetryPolicy.Handle <SocketException>().Or <BrokerUnreachableException>() .WaitAndRetry(_configutationRabbitMQ.RecconectCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))); }
public async void Subscribe(string topicName, SubscriptionDelegate subscriptionDelegate) { await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(topicName).Build()); mqttClient.ApplicationMessageReceived += async(s, e) => { if (topicName.Equals(e.ApplicationMessage.Topic)) { var decryptedMessage = await riksKit.Decrypt(e.ApplicationMessage.Payload); subscriptionDelegate(System.Text.Encoding.UTF8.GetString(decryptedMessage.SecretData)); } }; }
/// <summary> /// Subscribe for notification events. /// </summary> /// <param name="notificationDelegate">The delegate that handlers subscription.</param> /// <returns>The task <see cref="IEventBusSubscription"/> /// with <see cref="IDisposable"/> that can be used to remove the subscription.</returns> public Task <IEventBusSubscription> SubscribeAsync(SubscriptionDelegate <TNotification> notificationDelegate) { return(Task.Run(() => SubscribeSync(notificationDelegate))); }