public SubscriptionClient(IServiceBus bus, SubscriptionRouter router, Uri subscriptionServiceUri, TimeSpan startTimeout) { _bus = bus; _router = router; _subscriptionServiceUri = subscriptionServiceUri; _startTimeout = startTimeout; _network = router.Network; if (_log.IsDebugEnabled) _log.DebugFormat("Starting SubscriptionClient using {0}", subscriptionServiceUri); VerifyClientAndServiceNotOnSameEndpoint(bus); _ready.Reset(); var consumerInstance = new SubscriptionMessageConsumer(_router, _network); _unsubscribeAction = _bus.ControlBus.SubscribeInstance(consumerInstance); _unsubscribeAction += _bus.ControlBus.SubscribeContextHandler<SubscriptionRefresh>(Consume); _subscriptionEndpoint = _bus.GetEndpoint(subscriptionServiceUri); _producer = new SubscriptionServiceMessageProducer(router, _subscriptionEndpoint); WaitForSubscriptionServiceResponse(); }
/// <summary> /// Initializes a new instance of the <see cref="SubscriptionClient"/> class. /// </summary> /// <param name="bus">The bus.</param> /// <param name="router">The router.</param> /// <param name="subscriptionServiceUri">The subscription service URI.</param> /// <param name="startTimeout">The start timeout.</param> public SubscriptionClient(IServiceBus bus, SubscriptionRouter router, Uri subscriptionServiceUri, TimeSpan startTimeout) { _bus = bus; _router = router; _subscriptionServiceUri = subscriptionServiceUri; _startTimeout = startTimeout; _network = router.Network; if (_log.IsDebugEnabled) { _log.DebugFormat("Starting SubscriptionClient using {0}", subscriptionServiceUri); } VerifyClientAndServiceNotOnSameEndpoint(bus); _ready.Reset(); var consumerInstance = new SubscriptionMessageConsumer(_router, _network); _unsubscribeAction = _bus.ControlBus.SubscribeInstance(consumerInstance); _unsubscribeAction += _bus.ControlBus.SubscribeContextHandler <SubscriptionRefresh>(Consume); _subscriptionEndpoint = _bus.GetEndpoint(subscriptionServiceUri); _producer = new SubscriptionServiceMessageProducer(router, _subscriptionEndpoint); WaitForSubscriptionServiceResponse(); }
public MulticastSubscriptionClient(IServiceBus subscriptionBus, SubscriptionRouter router) { _subscriptionBus = subscriptionBus; _router = router; _network = router.Network; _peerId = router.PeerId; _peerUri = router.PeerUri; if (_log.IsDebugEnabled) { _log.DebugFormat("Starting MulticastSubscriptionService using {0}", subscriptionBus.Endpoint.Address); } var consumerInstance = new SubscriptionMessageConsumer(_router, _network); var msmqAddress = subscriptionBus.Endpoint.Address as IMsmqEndpointAddress; if (msmqAddress == null || msmqAddress.Uri.Scheme != MulticastMsmqTransportFactory.MulticastScheme) { throw new EndpointException(subscriptionBus.Endpoint.Address.Uri, "The multicast subscription client must be used on a multicast MSMQ endpoint"); } _producer = new BusSubscriptionMessageProducer(router, subscriptionBus.Endpoint, msmqAddress.InboundUri); _unsubscribeAction = _subscriptionBus.SubscribeInstance(consumerInstance); _unsubscribeAction += _subscriptionBus.SubscribeInstance(this); }
/// <summary> /// Initializes a new instance of the <see cref="SubscriptionMessageConsumer"/> class. /// </summary> /// <param name="router">The router.</param> /// <param name="network">The network.</param> /// <param name="ignoredSourceAddresses">The ignored source addresses.</param> public SubscriptionMessageConsumer(SubscriptionRouter router, string network, params Uri[] ignoredSourceAddresses) { _router = router; _peerId = router.PeerId; _peerUri = router.PeerUri; _network = network; _ignoredSourceAddresses = new HashSet <Uri>(ignoredSourceAddresses); }
public void SetUp() { var publishers = new Publishers(); publishers.AddOrReplacePublishers("A", new List<PublisherTableEntry> {new PublisherTableEntry(typeof(object), PublisherAddress.CreateFromPhysicalAddresses("publisher1"))}); router = new SubscriptionRouter(publishers, new EndpointInstances(), i => i.ToString()); dispatcher = new FakeDispatcher(); subscribeTerminator = new MessageDrivenSubscribeTerminator(router, "replyToAddress", "Endpoint", dispatcher); }
public SubscriptionObserver Create(IServiceBus bus, SubscriptionRouter router) { string path = bus.ControlBus.Endpoint.Address.Uri.AbsolutePath; var client = new SubscriptionClient(bus, router, _subscriptionServiceUri, _timeout); return client; }
public SubscriptionServiceMessageProducer(SubscriptionRouter router, IEndpoint endpoint) { _peerId = router.PeerId; _peerUri = router.PeerUri; _network = router.Network; _endpoint = endpoint; SendAddPeerMessage(); }
public void SetTargetCoordinator(SubscriptionRouter targetRouter) { lock (this) { _targetRouter = targetRouter; _waiting.ForEach(x => x(_targetRouter)); _waiting.Clear(); } }
public SubscriptionObserver Create(IServiceBus bus, SubscriptionRouter router) { string path = bus.ControlBus.Endpoint.Address.Uri.AbsolutePath; var client = new SubscriptionClient(bus, router, _subscriptionServiceUri, _timeout); return(client); }
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() { publishers = new Publishers(); publishers.AddOrReplacePublishers("A", new List <PublisherTableEntry> { new PublisherTableEntry(typeof(object), PublisherAddress.CreateFromPhysicalAddresses("publisher1")) }); router = new SubscriptionRouter(publishers, new EndpointInstances(), i => i.ToString()); dispatcher = new FakeDispatcher(); subscribeTerminator = new MessageDrivenSubscribeTerminator(router, "replyToAddress", "Endpoint", dispatcher); }
public BusSubscriptionMessageProducer(SubscriptionRouter router, IEndpoint endpoint, Uri endpointUri) { _peerId = router.PeerId; _peerUri = router.PeerUri; _network = router.Network; _endpoint = endpoint; _endpointUri = endpointUri; _timestamp = DateTime.UtcNow.Ticks; SendAddPeerMessage(); }
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>(); } }
void LoadSubscriptions(SubscriptionRouter router) { int messageNumber = 1; try { IEnumerable <PersistentSubscription> existing = _storage.Load(_busUri); var knownPeers = new HashSet <Guid>(); foreach (PersistentSubscription subscription in existing) { if (!knownPeers.Contains(subscription.PeerId)) { _log.DebugFormat("Loading peer: {0} {1}", subscription.PeerId, subscription.PeerUri); router.Send(new AddPeerMessage { PeerId = subscription.PeerId, PeerUri = subscription.PeerUri, Timestamp = subscription.Updated.Ticks, }); } _log.DebugFormat("Loading subscription: {0}", subscription); router.Send(new AddPeerSubscriptionMessage { PeerId = subscription.PeerId, SubscriptionId = subscription.SubscriptionId, EndpointUri = subscription.EndpointUri, MessageName = subscription.MessageName, CorrelationId = subscription.CorrelationId, MessageNumber = messageNumber++, }); } } catch (Exception ex) { _log.Error("Failed to load existing subscriptions", ex); } }
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>(); } }
void LoadSubscriptions(SubscriptionRouter router) { int messageNumber = 1; try { IEnumerable<PersistentSubscription> existing = _storage.Load(_busUri); var knownPeers = new HashSet<Guid>(); foreach (PersistentSubscription subscription in existing) { if (!knownPeers.Contains(subscription.PeerId)) { _log.DebugFormat("Loading peer: {0} {1}", subscription.PeerId, subscription.PeerUri); router.Send(new AddPeerMessage { PeerId = subscription.PeerId, PeerUri = subscription.PeerUri, Timestamp = subscription.Updated.Ticks, }); } _log.DebugFormat("Loading subscription: {0}", subscription); router.Send(new AddPeerSubscriptionMessage { PeerId = subscription.PeerId, SubscriptionId = subscription.SubscriptionId, EndpointUri = subscription.EndpointUri, MessageName = subscription.MessageName, CorrelationId = subscription.CorrelationId, MessageNumber = messageNumber++, }); } } catch (Exception ex) { _log.Error("Failed to load existing subscriptions", ex); } }
public SubscriptionLoopback(IServiceBus bus, SubscriptionRouter router) { _router = router; _peerId = CombGuid.Generate(); _waiting = new List<Action<SubscriptionRouter>>(); _ignoredMessageTypes = IgnoredMessageTypes(); WithTarget(x => { if (_log.IsDebugEnabled) _log.DebugFormat("Send AddPeer: {0}, {1}", _peerId, bus.ControlBus.Endpoint.Address.Uri); x.Send(new AddPeerMessage { PeerId = _peerId, PeerUri = bus.ControlBus.Endpoint.Address.Uri, Timestamp = DateTime.UtcNow.Ticks, }); }); }
public SubscriptionObserver Create(IServiceBus bus, SubscriptionRouter router) { string path = bus.ControlBus.Endpoint.Address.Uri.AbsolutePath; Uri uri = new UriBuilder("msmq-pgm", _multicastAddress.Address.ToString(), _multicastAddress.Port, path).Uri; Uri clientUri = uri.AppendToPath("_subscriptions"); var builder = new ControlBusBuilderImpl(new ServiceBusSettings { ConcurrentConsumerLimit = 1, ConcurrentReceiverLimit = 1, EndpointCache = bus.EndpointCache, InputAddress = clientUri, ReceiveTimeout = 3.Seconds(), Network = router.Network, AutoStart = true, }); IControlBus subscriptionBus = builder.Build(); var service = new MulticastSubscriptionClient(subscriptionBus, router); return(service); }
public SubscriptionObserver Create(IServiceBus bus, SubscriptionRouter router) { string path = bus.ControlBus.Endpoint.Address.Uri.AbsolutePath; Uri uri = new UriBuilder("msmq-pgm", _multicastAddress.Address.ToString(), _multicastAddress.Port, path).Uri; Uri clientUri = uri.AppendToPath("_subscriptions"); var builder = new ControlBusBuilderImpl(new ServiceBusSettings { ConcurrentConsumerLimit = 1, ConcurrentReceiverLimit = 1, EndpointCache = bus.EndpointCache, InputAddress = clientUri, ReceiveTimeout = 3.Seconds(), Network = router.Network, AutoStart = true, }); _subscriptionBus = builder.Build(); var service = new MulticastSubscriptionClient(_subscriptionBus, router, _group ?? router.PeerId.ToString()); return service; }
public SubscriptionLoopback(IServiceBus bus, SubscriptionRouter router) { _router = router; _peerId = CombGuid.Generate(); _waiting = new List <Action <SubscriptionRouter> >(); _ignoredMessageTypes = IgnoredMessageTypes(); WithTarget(x => { if (_log.IsDebugEnabled) { _log.DebugFormat("Send AddPeer: {0}, {1}", _peerId, bus.ControlBus.Endpoint.Address.Uri); } x.Send(new AddPeerMessage { PeerId = _peerId, PeerUri = bus.ControlBus.Endpoint.Address.Uri, Timestamp = DateTime.UtcNow.Ticks, }); }); }
public SubscriptionObserver Create(IServiceBus bus, SubscriptionRouter router) { var client = new SubscriptionClient(bus, router, _subscriptionServiceUri, _timeout); return client; }
/// <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>())); }
public SubscriptionObserver Create(IServiceBus bus, SubscriptionRouter router) { var client = new SubscriptionClient(bus, router, _subscriptionServiceUri, _timeout); return(client); }
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 Load(SubscriptionRouter router) { _fiber.Add(() => LoadSubscriptions(router)); }