public void Dispose() { _mockMerQurePublisher = null; _mockMessagingService = null; _publisher = null; _retryStrategy = null; }
private RetryStrategyConfiguration GetValidConfigurationWithPublishingDelay() { RetryStrategyConfiguration configuration = GetMinimalValidConfiguration(); configuration.DeliveryDelayInMilliseconds = 1000; return(configuration); }
private void CreateMainExchange(RetryStrategyConfiguration configuration) { _messagingService.DeclareExchange(configuration.BusName, Constants.ExchangeTypeTopic); foreach (Channel channel in configuration.Channels) { _messagingService.DeclareQueue(channel.Value); _messagingService.DeclareBinding(configuration.BusName, channel.Value, $"{channel.Value}.#"); } }
private void CreateRetryChannelsForOneDelay(RetryStrategyConfiguration configuration, string retryExchangeName, int delay) { foreach (Channel channel in configuration.Channels) { string retryQueueName = $"{channel.Value}.{delay}"; _messagingService.DeclareQueueWithDeadLetterPolicy(retryQueueName, configuration.BusName, delay, null); _messagingService.DeclareBinding(retryExchangeName, retryQueueName, $"{channel.Value}.{delay}", null); } }
public IBus <T> CreateNewBus <T>(RetryStrategyConfiguration configuration) where T : IDelivered { ApplyNewConfiguration(configuration); Publisher <T> producer = new Publisher <T>(_messagingService, configuration); RetryConsumer <T> consumer = new RetryConsumer <T>(_messagingService, configuration, producer); return(new Bus <T>(producer, consumer)); }
private RetryStrategyConfiguration GetValidConfigurationWithDelay() { RetryStrategyConfiguration configuration = GetMinimalValidConfiguration(); configuration.DelaysInMsBetweenEachRetry = new List <int> { 1000, 2000 }; return(configuration); }
private void CreateErrorExchange(RetryStrategyConfiguration configuration) { string errorExchangeName = $"{configuration.BusName}.{RetryStrategyConfiguration.ErrorExchangeSuffix}"; _messagingService.DeclareExchange(errorExchangeName, Constants.ExchangeTypeDirect); foreach (Channel channel in configuration.Channels) { string errorQueueName = $"{channel.Value}.{RetryStrategyConfiguration.ErrorExchangeSuffix}"; _messagingService.DeclareQueue(errorQueueName); _messagingService.DeclareBinding(errorExchangeName, errorQueueName, errorQueueName); } }
private void ApplyNewConfiguration(RetryStrategyConfiguration configuration) { if (configuration.Channels == null || !configuration.Channels.Any()) { throw new ArgumentNullException(nameof(configuration.Channels)); } if (configuration.DelaysInMsBetweenEachRetry == null) { throw new ArgumentNullException(nameof(configuration.Channels)); } CreateMainExchange(configuration); CreateRetryExchangeIfNecessary(configuration); CreateErrorExchange(configuration); }
/// <summary> /// Retry exchange is also used to delivery message with delay /// </summary> private void CreateRetryExchangeIfNecessary(RetryStrategyConfiguration configuration) { if (configuration.DelaysInMsBetweenEachRetry.Any() || configuration.DeliveryDelayInMilliseconds != 0) { string retryExchangeName = $"{configuration.BusName}.{RetryStrategyConfiguration.RetryExchangeSuffix}"; _messagingService.DeclareExchange(retryExchangeName, Constants.ExchangeTypeDirect); foreach (int delay in configuration.DelaysInMsBetweenEachRetry) { CreateRetryChannelsForOneDelay(configuration, retryExchangeName, delay); } if (!configuration.DelaysInMsBetweenEachRetry.Contains(configuration.DeliveryDelayInMilliseconds) && configuration.DeliveryDelayInMilliseconds != 0) { CreateRetryChannelsForOneDelay(configuration, retryExchangeName, configuration.DeliveryDelayInMilliseconds); } } }
public SampleService(IRetryBusService retryBusService) { _retryBusService = retryBusService; RetryStrategyConfiguration sampleConfiguration = new RetryStrategyConfiguration { Channels = SampleChannels.GetAllChannels(), BusName = BusName, DelaysInMsBetweenEachRetry = new List <int> { { 5000 }, { 6000 }, { 10000 } }, MessageIsGoingIntoErrorBusAfterAllRepeat = true, DeliveryDelayInMilliseconds = 1000 }; SampleBus = _retryBusService.CreateNewBus <Sample>(sampleConfiguration); }
public PublisherTests() { _mockMerQurePublisher = new Mock <IPublisher>(); _mockMessagingService = new Mock <IMessagingService>(); _retryStrategy = new RetryStrategyConfiguration() { BusName = "testBus", Channels = new List <Channel>() { new Channel("testChannel") }, DelaysInMsBetweenEachRetry = new List <int>() { 1000, 2000 }, DeliveryDelayInMilliseconds = 0, MessageIsGoingIntoErrorBusAfterAllRepeat = false }; _publisher = new Publisher <TestMessage>(_mockMessagingService.Object, _retryStrategy); }
public Publisher(IMessagingService messagingService, RetryStrategyConfiguration retryConfiguration) { _messagingService = messagingService; _messageBrokerConfiguration = retryConfiguration; }
public RetryConsumer(IMessagingService messagingService, RetryStrategyConfiguration retryConfiguration, Publisher <T> producer) : base(messagingService) { _retryConfiguration = retryConfiguration; _producer = producer; }