public void Should_move_to_error_queue_based_on_retry_policy() { var action = GatewayRecoverabilityPolicy.Invoke(context, (message, exception, retry) => TimeSpan.MinValue, config); Assert.IsInstanceOf <MoveToError>(action, "MoveToError recoverability action was expected"); var moveToErrorAction = action as MoveToError; Assert.AreEqual(config.Failed.ErrorQueue, moveToErrorAction.ErrorQueue, "MoveToError recoverability action has wrong error queue"); }
public void Should_make_delayed_retry_based_on_retry_policy() { var requestedDelay = TimeSpan.FromSeconds(10); var action = GatewayRecoverabilityPolicy.Invoke(context, (message, exception, retry) => requestedDelay, config); Assert.IsInstanceOf <DelayedRetry>(action, "DelayedRetry recoverability action was expected"); var delayedRetryAction = action as DelayedRetry; Assert.AreEqual(requestedDelay, delayedRetryAction.Delay, "DelayedRetry recoverability action has wrong delay"); }
public void Should_call_retry_policy_with_current_retry_number() { var retryPolicyCalled = false; var currentRetry = 0; GatewayRecoverabilityPolicy.Invoke(context, (message, exception, retry) => { retryPolicyCalled = true; currentRetry = retry; return(TimeSpan.MinValue); }, config); Assert.IsTrue(retryPolicyCalled, "Retry policy was not called by the recoverability policy"); Assert.AreEqual(context.DelayedDeliveriesPerformed + 1, currentRetry, "Retry policy was called with wrong retry number"); }
/// <summary> /// Called when the features is activated /// </summary> protected override void Setup(FeatureConfigurationContext context) { var storageConfiguration = context.Settings.Get <GatewayDeduplicationConfiguration>(); storageConfiguration.Setup(context.Settings); var transportDefinition = context.Settings.Get <TransportDefinition>(); ConfigureTransaction(context); var channelManager = CreateChannelManager(context.Settings); RegisterChannels(context, channelManager, out var channelSenderFactory, out var channelReceiverFactory); var logicalAddress = new QueueAddress(context.Settings.EndpointQueueName(), null, null, "gateway"); var gatewayInputAddress = transportDefinition.ToTransportAddress(logicalAddress); var retryPolicy = context.Settings.Get <Func <IncomingMessage, Exception, int, TimeSpan> >("Gateway.Retries.RetryPolicy"); var sender = new GatewayMessageSender( gatewayInputAddress, channelManager, new MessageNotifier(), context.Settings.LocalAddress(), GetConfigurationBasedSiteRouter(context)); context.AddSatelliteReceiver("Gateway", gatewayInputAddress, PushRuntimeSettings.Default, (config, errorContext) => GatewayRecoverabilityPolicy.Invoke(errorContext, retryPolicy, config), (builder, messageContext, cancellationToken) => sender.SendToDestination(messageContext, builder.GetRequiredService <IMessageDispatcher>(), CreateForwarder(channelSenderFactory, builder.GetServices <IDataBus>()?.FirstOrDefault()), cancellationToken)); var configuredSitesKeys = GatewaySettings.GetConfiguredSites(context.Settings) .Select(s => s.Key) .ToList(); context.Pipeline.Register("RouteToGateway", new RouteToGatewayBehavior(gatewayInputAddress, configuredSitesKeys), "Reroutes gateway messages to the gateway"); context.Pipeline.Register("GatewayIncomingBehavior", new GatewayIncomingBehavior(), "Extracts gateway related information from the incoming message"); context.Pipeline.Register("GatewayOutgoingBehavior", new GatewayOutgoingBehavior(), "Puts gateway related information on the headers of outgoing messages"); context.RegisterStartupTask(b => new GatewayReceiverStartupTask( channelManager, channelReceiverFactory, GetEndpointRouter(context), b.GetRequiredService <IMessageDispatcher>(), storageConfiguration.CreateStorage(b), b.GetServices <IDataBus>()?.FirstOrDefault(), gatewayInputAddress, transportDefinition.TransportTransactionMode)); }
/// <summary> /// Called when the features is activated /// </summary> protected override void Setup(FeatureConfigurationContext context) { if (context.Settings.TryGet("ResultingSupportedStorages", out List <Type> supportedStorages)) { if (!supportedStorages.Contains(typeof(StorageType.GatewayDeduplication))) { throw new Exception("The selected persistence doesn't have support for gateway deduplication storage. Please configure one that supports gateway deduplication storage."); } } else { throw new Exception("No persistence configured, please configure one that supports gateway deduplication storage."); } ConfigureTransaction(context); var channelManager = CreateChannelManager(context.Settings); RegisterChannels(context, channelManager, out var channelSenderFactory, out var channelReceiverFactory); var gatewayInputAddress = context.Settings.GetTransportAddress(context.Settings.LogicalAddress().CreateQualifiedAddress("gateway")); var retryPolicy = context.Settings.Get <Func <IncomingMessage, Exception, int, TimeSpan> >("Gateway.Retries.RetryPolicy"); var sender = new GatewayMessageSender( gatewayInputAddress, channelManager, new MessageNotifier(), context.Settings.LocalAddress(), GetConfigurationBasedSiteRouter(context)); context.AddSatelliteReceiver("Gateway", gatewayInputAddress, PushRuntimeSettings.Default, (config, errorContext) => GatewayRecoverabilityPolicy.Invoke(errorContext, retryPolicy, config), (builder, messageContext) => sender.SendToDestination(messageContext, builder.Build <IDispatchMessages>(), CreateForwarder(channelSenderFactory, builder.BuildAll <IDataBus>()?.FirstOrDefault()))); context.Pipeline.Register("RouteToGateway", new RouteToGatewayBehavior(gatewayInputAddress), "Reroutes gateway messages to the gateway"); context.Pipeline.Register("GatewayIncomingBehavior", new GatewayIncomingBehavior(), "Extracts gateway related information from the incoming message"); context.Pipeline.Register("GatewayOutgoingBehavior", new GatewayOutgoingBehavior(), "Puts gateway related information on the headers of outgoing messages"); context.RegisterStartupTask(b => new GatewayReceiverStartupTask(channelManager, channelReceiverFactory, GetEndpointRouter(context), b.Build <IDispatchMessages>(), b.Build <IDeduplicateMessages>(), b.BuildAll <IDataBus>()?.FirstOrDefault(), gatewayInputAddress)); }