public void Setup() { metadataRegistry = new MessageMetadataRegistry(new Conventions()); endpointInstances = new EndpointInstances(); subscriptionStorage = new FakeSubscriptionStorage(); router = new UnicastPublishRouter( metadataRegistry, subscriptionStorage); }
protected internal override void Setup(FeatureConfigurationContext context) { var transportDefinition = context.Settings.Get <TransportDefinition>(); var canReceive = !context.Settings.GetOrDefault <bool>("Endpoint.SendOnly"); var distributionPolicy = context.Routing.DistributionPolicy; var publishers = context.Routing.Publishers; var configuredPublishers = context.Settings.Get <ConfiguredPublishers>(); var conventions = context.Settings.Get <Conventions>(); var enforceBestPractices = context.Routing.EnforceBestPractices; configuredPublishers.Apply(publishers, conventions, enforceBestPractices); context.Pipeline.Register(b => { var unicastPublishRouter = new UnicastPublishRouter(b.GetRequiredService <MessageMetadataRegistry>(), i => { var queueAddress = new QueueAddress(i.Endpoint, i.Discriminator, i.Properties, null); return(transportDefinition.ToTransportAddress(queueAddress)); }, b.GetRequiredService <ISubscriptionStorage>()); return(new MigrationModePublishConnector(distributionPolicy, unicastPublishRouter)); }, "Determines how the published messages should be routed"); if (canReceive) { var endpointInstances = context.Routing.EndpointInstances; var subscriptionRouter = new SubscriptionRouter(publishers, endpointInstances, i => { var queueAddress = new QueueAddress(i.Endpoint, i.Discriminator, i.Properties, null); return(transportDefinition.ToTransportAddress(queueAddress)); }); var subscriberAddress = context.Receiving.LocalAddress; context.Pipeline.Register(b => new MigrationSubscribeTerminator(b.GetRequiredService <ISubscriptionManager>(), b.GetRequiredService <MessageMetadataRegistry>(), subscriptionRouter, b.GetRequiredService <IMessageDispatcher>(), subscriberAddress, context.Settings.EndpointName()), "Requests the transport to subscribe to a given message type"); context.Pipeline.Register(b => new MigrationUnsubscribeTerminator(b.GetRequiredService <ISubscriptionManager>(), b.GetRequiredService <MessageMetadataRegistry>(), subscriptionRouter, b.GetRequiredService <IMessageDispatcher>(), subscriberAddress, context.Settings.EndpointName()), "Sends requests to unsubscribe when message driven subscriptions is in use"); var authorizer = context.Settings.GetSubscriptionAuthorizer(); if (authorizer == null) { authorizer = _ => true; } context.Container.AddSingleton(authorizer); context.Pipeline.Register(typeof(SubscriptionReceiverBehavior), "Check for subscription messages and execute the requested behavior to subscribe or unsubscribe."); } else { context.Pipeline.Register(new SendOnlySubscribeTerminator(), "Throws an exception when trying to subscribe from a send-only endpoint"); context.Pipeline.Register(new SendOnlyUnsubscribeTerminator(), "Throws an exception when trying to unsubscribe from a send-only endpoint"); } // implementations of IInitializableSubscriptionStorage are optional and can be provided by persisters. context.RegisterStartupTask(b => new MessageDrivenSubscriptions.InitializableSubscriptionStorage(b.GetService <IInitializableSubscriptionStorage>())); }
public void Setup() { metadataRegistry = new MessageMetadataRegistry(_ => true); endpointInstances = new EndpointInstances(); subscriptionStorage = new FakeSubscriptionStorage(); router = new UnicastPublishRouter( metadataRegistry, i => string.Empty, subscriptionStorage); }
protected internal override void Setup(FeatureConfigurationContext context) { var transportInfrastructure = context.Settings.Get <TransportInfrastructure>(); var canReceive = !context.Settings.GetOrDefault <bool>("Endpoint.SendOnly"); var distributionPolicy = context.Routing.DistributionPolicy; var publishers = context.Routing.Publishers; var configuredPublishers = context.Settings.Get <ConfiguredPublishers>(); var conventions = context.Settings.Get <Conventions>(); var enforceBestPractices = context.Routing.EnforceBestPractices; configuredPublishers.Apply(publishers, conventions, enforceBestPractices); context.Pipeline.Register(b => { var unicastPublishRouter = new UnicastPublishRouter(b.Build <MessageMetadataRegistry>(), i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)), b.Build <ISubscriptionStorage>()); return(new MigrationModePublishConnector(distributionPolicy, unicastPublishRouter)); }, "Determines how the published messages should be routed"); if (canReceive) { var endpointInstances = context.Routing.EndpointInstances; var transportSubscriptionInfrastructure = transportInfrastructure.ConfigureSubscriptionInfrastructure(); var subscriptionManager = transportSubscriptionInfrastructure.SubscriptionManagerFactory(); var subscriptionRouter = new SubscriptionRouter(publishers, endpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); var subscriberAddress = context.Receiving.LocalAddress; context.Pipeline.Register(b => new MigrationSubscribeTerminator(subscriptionManager, subscriptionRouter, b.Build <IDispatchMessages>(), subscriberAddress, context.Settings.EndpointName()), "Requests the transport to subscribe to a given message type"); context.Pipeline.Register(b => new MigrationUnsubscribeTerminator(subscriptionManager, subscriptionRouter, b.Build <IDispatchMessages>(), subscriberAddress, context.Settings.EndpointName()), "Sends requests to unsubscribe when message driven subscriptions is in use"); var authorizer = context.Settings.GetSubscriptionAuthorizer(); if (authorizer == null) { authorizer = _ => true; } context.Container.RegisterSingleton(authorizer); context.Pipeline.Register(typeof(SubscriptionReceiverBehavior), "Check for subscription messages and execute the requested behavior to subscribe or unsubscribe."); } else { context.Pipeline.Register(new SendOnlySubscribeTerminator(), "Throws an exception when trying to subscribe from a send-only endpoint"); context.Pipeline.Register(new SendOnlyUnsubscribeTerminator(), "Throws an exception when trying to unsubscribe from a send-only endpoint"); } context.Container.ConfigureComponent <MessageDrivenSubscriptionsToBeRefactored.InitializableSubscriptionStorage>(DependencyLifecycle.SingleInstance); context.RegisterStartupTask(b => b.Build <MessageDrivenSubscriptionsToBeRefactored.InitializableSubscriptionStorage>()); }
/// <summary> /// See <see cref="Feature.Setup" />. /// </summary> protected internal override void Setup(FeatureConfigurationContext context) { // The MessageDrivenSubscriptions feature needs to be activated when using the subscription migration mode as some persister packages check this feature before enabling the subscription storage. if (SubscriptionMigrationMode.IsMigrationModeEnabled(context.Settings)) { return; } if (!PersistenceStartup.HasSupportFor <StorageType.Subscriptions>(context.Settings)) { throw new Exception("The selected persistence doesn't have support for subscription storage. Select another persistence or disable the message-driven subscriptions feature using endpointConfiguration.DisableFeature<MessageDrivenSubscriptions>()"); } var transportInfrastructure = context.Settings.Get <TransportInfrastructure>(); var canReceive = !context.Settings.GetOrDefault <bool>("Endpoint.SendOnly"); var conventions = context.Settings.Get <Conventions>(); var enforceBestPractices = context.Routing.EnforceBestPractices; var distributionPolicy = context.Routing.DistributionPolicy; var endpointInstances = context.Routing.EndpointInstances; var publishers = context.Routing.Publishers; var configuredPublishers = context.Settings.Get <ConfiguredPublishers>(); configuredPublishers.Apply(publishers, conventions, enforceBestPractices); context.Pipeline.Register(b => { var unicastPublishRouter = new UnicastPublishRouter(b.Build <MessageMetadataRegistry>(), i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)), b.Build <ISubscriptionStorage>()); return(new UnicastPublishRouterConnector(unicastPublishRouter, distributionPolicy)); }, "Determines how the published messages should be routed"); if (canReceive) { var subscriberAddress = context.Receiving.LocalAddress; var subscriptionRouter = new SubscriptionRouter(publishers, endpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); context.Pipeline.Register(b => new MessageDrivenSubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.Build <IDispatchMessages>()), "Sends subscription requests when message driven subscriptions is in use"); context.Pipeline.Register(b => new MessageDrivenUnsubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.Build <IDispatchMessages>()), "Sends requests to unsubscribe when message driven subscriptions is in use"); var authorizer = context.Settings.GetSubscriptionAuthorizer(); if (authorizer == null) { authorizer = _ => true; } context.Container.RegisterSingleton(authorizer); context.Pipeline.Register <SubscriptionReceiverBehavior.Registration>(); } }
/// <summary> /// See <see cref="Feature.Setup" />. /// </summary> protected internal override void Setup(FeatureConfigurationContext context) { if (!PersistenceStartup.HasSupportFor<StorageType.Subscriptions>(context.Settings)) { throw new Exception("The selected persistence doesn't have support for subscription storage. Select another persistence or disable the message-driven subscriptions feature using endpointConfiguration.DisableFeature<MessageDrivenSubscriptions>()"); } var transportInfrastructure = context.Settings.Get<TransportInfrastructure>(); var canReceive = !context.Settings.GetOrDefault<bool>("Endpoint.SendOnly"); var conventions = context.Settings.Get<Conventions>(); var enforceBestPractices = context.Settings.Get<bool>(RoutingFeature.EnforceBestPracticesSettingsKey); var distributionPolicy = context.Settings.Get<DistributionPolicy>(); var endpointInstances = context.Settings.Get<EndpointInstances>(); var publishers = context.Settings.Get<Publishers>(); var configuredPublishers = context.Settings.Get<ConfiguredPublishers>(); configuredPublishers.Apply(publishers, conventions, enforceBestPractices); context.Pipeline.Register(b => { var unicastPublishRouter = new UnicastPublishRouter(b.Build<MessageMetadataRegistry>(), b.Build<ISubscriptionStorage>()); return new UnicastPublishRouterConnector(unicastPublishRouter, distributionPolicy); }, "Determines how the published messages should be routed"); if (canReceive) { var distributorAddress = context.Settings.GetOrDefault<string>("LegacyDistributor.Address"); var subscriberAddress = distributorAddress ?? context.Settings.LocalAddress(); var subscriptionRouter = new SubscriptionRouter(publishers, endpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); context.Pipeline.Register(b => new MessageDrivenSubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.Build<IDispatchMessages>()), "Sends subscription requests when message driven subscriptions is in use"); context.Pipeline.Register(b => new MessageDrivenUnsubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.Build<IDispatchMessages>()), "Sends requests to unsubscribe when message driven subscriptions is in use"); var authorizer = context.Settings.GetSubscriptionAuthorizer(); if (authorizer == null) { authorizer = _ => true; } context.Container.RegisterSingleton(authorizer); context.Pipeline.Register<SubscriptionReceiverBehavior.Registration>(); } }
protected internal override void Setup(FeatureConfigurationContext context) { var transportInfrastructure = context.Settings.Get <TransportInfrastructure>(); var canReceive = !context.Settings.GetOrDefault <bool>("Endpoint.SendOnly"); var distributionPolicy = context.Routing.DistributionPolicy; var publishers = context.Routing.Publishers; var configuredPublishers = context.Settings.Get <ConfiguredPublishers>(); var conventions = context.Settings.Get <Conventions>(); var enforceBestPractices = context.Routing.EnforceBestPractices; configuredPublishers.Apply(publishers, conventions, enforceBestPractices); context.Pipeline.Register(b => { var unicastPublishRouter = new UnicastPublishRouter(b.Build <MessageMetadataRegistry>(), i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)), b.Build <ISubscriptionStorage>()); return(new MigrationRouterConnector(distributionPolicy, unicastPublishRouter)); }, "Determines how the published messages should be routed"); if (canReceive) { var endpointInstances = context.Routing.EndpointInstances; var transportSubscriptionInfrastructure = transportInfrastructure.ConfigureSubscriptionInfrastructure(); var subscriptionManager = transportSubscriptionInfrastructure.SubscriptionManagerFactory(); var subscriptionRouter = new SubscriptionRouter(publishers, endpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); var subscriberAddress = context.Receiving.LocalAddress; context.Pipeline.Register(b => new MigrationSubscribeTerminator(subscriptionManager, subscriptionRouter, b.Build <IDispatchMessages>(), subscriberAddress, context.Settings.EndpointName()), "Requests the transport to subscribe to a given message type"); context.Pipeline.Register(b => new MigrationUnsubscribeTerminator(subscriptionManager, subscriptionRouter, b.Build <IDispatchMessages>(), subscriberAddress, context.Settings.EndpointName()), "Sends requests to unsubscribe when message driven subscriptions is in use"); var authorizer = context.Settings.GetSubscriptionAuthorizer(); if (authorizer == null) { authorizer = _ => true; } context.Container.RegisterSingleton(authorizer); context.Pipeline.Register <SubscriptionReceiverBehavior.Registration>(); } }
/// <summary> /// See <see cref="Feature.Setup" />. /// </summary> protected internal override void Setup(FeatureConfigurationContext context) { // The MessageDrivenSubscriptions feature needs to be activated when using the subscription migration mode as some persister packages check this feature before enabling the subscription storage. if (SubscriptionMigrationMode.IsMigrationModeEnabled(context.Settings)) { return; } var transportDefinition = context.Settings.Get <TransportDefinition>(); var conventions = context.Settings.Get <Conventions>(); var enforceBestPractices = context.Routing.EnforceBestPractices; var distributionPolicy = context.Routing.DistributionPolicy; var endpointInstances = context.Routing.EndpointInstances; var publishers = context.Routing.Publishers; var configuredPublishers = context.Settings.Get <ConfiguredPublishers>(); configuredPublishers.Apply(publishers, conventions, enforceBestPractices); var publishingEnabled = context.Settings.Get <bool>(EnablePublishingSettingsKey); if (publishingEnabled) { if (!PersistenceStartup.HasSupportFor <StorageType.Subscriptions>(context.Settings)) { throw new Exception("The selected persistence doesn't have support for subscription storage. Select another persistence or disable the publish functionality using transportConfiguration.DisablePublishing()"); } context.Pipeline.Register("UnicastPublishRouterConnector", b => { var unicastPublishRouter = new UnicastPublishRouter(b.GetRequiredService <MessageMetadataRegistry>(), i => transportDefinition.ToTransportAddress(new QueueAddress(i.Endpoint, i.Discriminator, i.Properties, null)), b.GetRequiredService <ISubscriptionStorage>()); return(new UnicastPublishConnector(unicastPublishRouter, distributionPolicy)); }, "Determines how the published messages should be routed"); var authorizer = context.Settings.GetSubscriptionAuthorizer(); if (authorizer == null) { authorizer = _ => true; } context.Container.AddSingleton(authorizer); context.Pipeline.Register(typeof(SubscriptionReceiverBehavior), "Check for subscription messages and execute the requested behavior to subscribe or unsubscribe."); } else { context.Pipeline.Register(typeof(DisabledPublishingTerminator), "Throws an exception when trying to publish with publishing disabled"); } var canReceive = !context.Settings.GetOrDefault <bool>("Endpoint.SendOnly"); if (canReceive) { var subscriberAddress = context.Receiving.LocalAddress; var subscriptionRouter = new SubscriptionRouter(publishers, endpointInstances, i => transportDefinition.ToTransportAddress(new QueueAddress(i.Endpoint, i.Discriminator, i.Properties, null))); context.Pipeline.Register(b => new MessageDrivenSubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.GetRequiredService <IMessageDispatcher>()), "Sends subscription requests when message driven subscriptions is in use"); context.Pipeline.Register(b => new MessageDrivenUnsubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.GetRequiredService <IMessageDispatcher>()), "Sends requests to unsubscribe when message driven subscriptions is in use"); } else { context.Pipeline.Register(new SendOnlySubscribeTerminator(), "Throws an exception when trying to subscribe from a send-only endpoint"); context.Pipeline.Register(new SendOnlyUnsubscribeTerminator(), "Throws an exception when trying to unsubscribe from a send-only endpoint"); } // implementations of IInitializableSubscriptionStorage are optional and can be provided by persisters. context.RegisterStartupTask(b => new InitializableSubscriptionStorage(b.GetService <IInitializableSubscriptionStorage>())); }
protected internal override void Setup(FeatureConfigurationContext context) { var canReceive = !context.Settings.GetOrDefault <bool>("Endpoint.SendOnly"); var transportInfrastructure = context.Settings.Get <TransportInfrastructure>(); var unicastRoutingTable = context.Settings.Get <UnicastRoutingTable>(); var endpointInstances = context.Settings.Get <EndpointInstances>(); var publishers = context.Settings.Get <Publishers>(); var distributionPolicy = context.Settings.Get <DistributionPolicy>(); var configuredUnicastRoutes = context.Settings.Get <ConfiguredUnicastRoutes>(); var configuredPublishers = context.Settings.Get <ConfiguredPublishers>(); var conventions = context.Settings.Get <Conventions>(); var unicastBusConfig = context.Settings.GetConfigSection <UnicastBusConfig>(); var enforceBestPractices = context.Settings.Get <bool>(EnforceBestPracticesSettingsKey); if (enforceBestPractices) { EnableBestPracticeEnforcement(context); } unicastBusConfig?.MessageEndpointMappings.Apply(publishers, unicastRoutingTable, transportInfrastructure.MakeCanonicalForm, conventions); configuredUnicastRoutes.Apply(unicastRoutingTable, conventions); configuredPublishers.Apply(publishers, conventions, enforceBestPractices); var outboundRoutingPolicy = transportInfrastructure.OutboundRoutingPolicy; context.Pipeline.Register(b => { var unicastSendRouter = new UnicastSendRouter(unicastRoutingTable, endpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); return(new UnicastSendRouterConnector(context.Settings.LocalAddress(), context.Settings.InstanceSpecificQueue(), unicastSendRouter, distributionPolicy, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)))); }, "Determines how the message being sent should be routed"); context.Pipeline.Register(new UnicastReplyRouterConnector(), "Determines how replies should be routed"); if (outboundRoutingPolicy.Publishes == OutboundRoutingType.Unicast) { context.Pipeline.Register(b => { var unicastPublishRouter = new UnicastPublishRouter(b.Build <MessageMetadataRegistry>(), b.Build <ISubscriptionStorage>()); return(new UnicastPublishRouterConnector(unicastPublishRouter, distributionPolicy)); }, "Determines how the published messages should be routed"); } else { context.Pipeline.Register(new MulticastPublishRouterBehavior(), "Determines how the published messages should be routed"); } if (canReceive) { var publicReturnAddress = context.Settings.GetOrDefault <string>("PublicReturnAddress"); var distributorAddress = context.Settings.GetOrDefault <string>("LegacyDistributor.Address"); context.Pipeline.Register(new ApplyReplyToAddressBehavior(context.Settings.LocalAddress(), context.Settings.InstanceSpecificQueue(), publicReturnAddress, distributorAddress), "Applies the public reply to address to outgoing messages"); if (outboundRoutingPolicy.Publishes == OutboundRoutingType.Unicast) { var subscriberAddress = distributorAddress ?? context.Settings.LocalAddress(); var subscriptionRouter = new SubscriptionRouter(publishers, endpointInstances, i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i))); context.Pipeline.Register(b => new MessageDrivenSubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.Build <IDispatchMessages>()), "Sends subscription requests when message driven subscriptions is in use"); context.Pipeline.Register(b => new MessageDrivenUnsubscribeTerminator(subscriptionRouter, subscriberAddress, context.Settings.EndpointName(), b.Build <IDispatchMessages>()), "Sends requests to unsubscribe when message driven subscriptions is in use"); } else { var transportSubscriptionInfrastructure = transportInfrastructure.ConfigureSubscriptionInfrastructure(); var subscriptionManager = transportSubscriptionInfrastructure.SubscriptionManagerFactory(); context.Pipeline.Register(new NativeSubscribeTerminator(subscriptionManager), "Requests the transport to subscribe to a given message type"); context.Pipeline.Register(new NativeUnsubscribeTerminator(subscriptionManager), "Requests the transport to unsubscribe to a given message type"); } } }
public void Setup() { metadataRegistry = new MessageMetadataRegistry(new Conventions()); endpointInstances = new EndpointInstances(); subscriptionStorage = new FakeSubscriptionStorage(); router = new UnicastPublishRouter( metadataRegistry, subscriptionStorage); }