/// <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));
        }
예제 #2
0
        static string SetupDispatcherSatellite(FeatureConfigurationContext context, TransportTransactionMode requiredTransactionSupport)
        {
            var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("TimeoutsDispatcher");
            var satelliteAddress        = context.Settings.GetTransportAddress(satelliteLogicalAddress);

            context.AddSatelliteReceiver("Timeout Dispatcher Processor", satelliteAddress, requiredTransactionSupport, PushRuntimeSettings.Default, RecoverabilityPolicy,
                                         (builder, pushContext) =>
            {
                var dispatchBehavior = new DispatchTimeoutBehavior(
                    builder.Build <IDispatchMessages>(),
                    builder.Build <IPersistTimeouts>(),
                    requiredTransactionSupport);

                return(dispatchBehavior.Invoke(pushContext));
            });

            return(satelliteAddress);
        }
예제 #3
0
        static string SetupDispatcherSatellite(FeatureConfigurationContext context, TransportTransactionMode requiredTransactionSupport, PushRuntimeSettings pushRuntimeSettings)
        {
            var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("TimeoutsDispatcher");
            var satelliteAddress = context.Settings.GetTransportAddress(satelliteLogicalAddress);

            context.AddSatelliteReceiver("Timeout Dispatcher Processor", satelliteAddress, requiredTransactionSupport, pushRuntimeSettings, RecoverabilityPolicy,
                (builder, pushContext) =>
                {
                    var dispatchBehavior = new DispatchTimeoutBehavior(
                        builder.Build<IDispatchMessages>(),
                        builder.Build<IPersistTimeouts>(),
                        requiredTransactionSupport);

                    return dispatchBehavior.Invoke(pushContext);
                });

            return satelliteAddress;
        }
예제 #4
0
        static void SetupStorageSatellite(FeatureConfigurationContext context, PushRuntimeSettings pushRuntimeSettings)
        {
            var satelliteLogicalAddress = context.Receiving.LogicalAddress.CreateQualifiedAddress("Timeouts");
            var satelliteAddress        = context.Settings.GetTransportAddress(satelliteLogicalAddress);

            context.AddSatelliteReceiver("Timeout Message Processor", satelliteAddress, pushRuntimeSettings, RecoverabilityPolicy,
                                         (builder, messageContext) =>
            {
                var storeBehavior = new StoreTimeoutBehavior(
                    builder.GetRequiredService <ExpiredTimeoutsPoller>(),
                    builder.GetRequiredService <IDispatchMessages>(),
                    builder.GetRequiredService <IPersistTimeouts>(),
                    context.Settings.EndpointName());

                return(storeBehavior.Invoke(messageContext));
            });

            context.Settings.Get <TimeoutManagerAddressConfiguration>().Set(satelliteAddress);
        }
예제 #5
0
        static void SetupStorageSatellite(FeatureConfigurationContext context, TransportTransactionMode requiredTransactionSupport)
        {
            var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("Timeouts");
            var satelliteAddress        = context.Settings.GetTransportAddress(satelliteLogicalAddress);

            context.AddSatelliteReceiver("Timeout Message Processor", satelliteAddress, requiredTransactionSupport, PushRuntimeSettings.Default, RecoverabilityPolicy,
                                         (builder, pushContext) =>
            {
                var storeBehavior = new StoreTimeoutBehavior(
                    builder.Build <ExpiredTimeoutsPoller>(),
                    builder.Build <IDispatchMessages>(),
                    builder.Build <IPersistTimeouts>(),
                    context.Settings.EndpointName().ToString());

                return(storeBehavior.Invoke(pushContext));
            });

            context.Settings.Get <TimeoutManagerAddressConfiguration>().Set(satelliteAddress);
        }
예제 #6
0
        /// <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));
        }
예제 #7
0
        static void SetupStorageSatellite(FeatureConfigurationContext context, TransportTransactionMode requiredTransactionSupport, PushRuntimeSettings pushRuntimeSettings)
        {
            var satelliteLogicalAddress = context.Settings.LogicalAddress().CreateQualifiedAddress("Timeouts");
            var satelliteAddress = context.Settings.GetTransportAddress(satelliteLogicalAddress);

            context.AddSatelliteReceiver("Timeout Message Processor", satelliteAddress, requiredTransactionSupport, pushRuntimeSettings, RecoverabilityPolicy,
                (builder, pushContext) =>
                {
                    var storeBehavior = new StoreTimeoutBehavior(
                        builder.Build<ExpiredTimeoutsPoller>(),
                        builder.Build<IDispatchMessages>(),
                        builder.Build<IPersistTimeouts>(),
                        context.Settings.EndpointName().ToString());

                    return storeBehavior.Invoke(pushContext);
                });

            context.Settings.Get<TimeoutManagerAddressConfiguration>().Set(satelliteAddress);
        }