Ejemplo n.º 1
0
        public void When_same_publisher_is_registered_multiple_times_should_remove_duplicates()
        {
            var publisherTable = new Publishers();

            var pub1 = PublisherAddress.CreateFromEndpointName("Endpoint1");
            var pub2 = PublisherAddress.CreateFromEndpointName("Endpoint1");
            var pub3 = PublisherAddress.CreateFromEndpointInstances(new EndpointInstance("Instance1"), new EndpointInstance("Instance2"));
            var pub4 = PublisherAddress.CreateFromEndpointInstances(new EndpointInstance("Instance1"), new EndpointInstance("Instance2"));
            var pub5 = PublisherAddress.CreateFromPhysicalAddresses("address1", "address2");
            var pub6 = PublisherAddress.CreateFromPhysicalAddresses("address1", "address2");

            publisherTable.AddOrReplacePublishers("key2", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), pub1),
                new PublisherTableEntry(typeof(MyEvent), pub2),
                new PublisherTableEntry(typeof(MyEvent), pub3),
                new PublisherTableEntry(typeof(MyEvent), pub4),
                new PublisherTableEntry(typeof(MyEvent), pub5),
                new PublisherTableEntry(typeof(MyEvent), pub6)
            });

            var pubs = publisherTable.GetPublisherFor(typeof(MyEvent)).ToArray();

            Assert.AreEqual(3, pubs.Length);
            Assert.Contains(pub1, pubs);
            Assert.Contains(pub2, pubs);
            Assert.Contains(pub3, pubs);
            Assert.Contains(pub4, pubs);
            Assert.Contains(pub5, pubs);
            Assert.Contains(pub6, pubs);
        }
Ejemplo n.º 2
0
 public static void RegisterPublisher(this RoutingSettings config, Type eventType, string publisherEndpoint)
 {
     config.GetSettings().GetOrCreate <Publishers>().AddOrReplacePublishers(Guid.NewGuid().ToString(),
                                                                            new List <PublisherTableEntry> {
         new PublisherTableEntry(eventType, PublisherAddress.CreateFromEndpointName(publisherEndpoint))
     });
 }
Ejemplo n.º 3
0
        public async Task It_should_still_deliver_once()
        {
            var context = await Scenario.Define <Context>()
                          .WithEndpoint <Publisher>(b => b.When(c => c.Instance1SubscribedMessageDriven && c.Instance2SubscribedNative, (session, ctx) => session.Publish(new MyEvent())))
                          .WithEndpoint(new Subscriber(false), b =>
            {
                b.CustomConfig(c =>
                {
                    c.GetSettings().GetOrCreate <Publishers>().AddOrReplacePublishers("LegacyConfig", new List <PublisherTableEntry>
                    {
                        new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(Conventions.EndpointNamingConvention(typeof(Publisher))))
                    });
                });
                b.When(async(session, ctx) =>
                {
                    await session.Subscribe <MyEvent>();
                });
            })
                          .WithEndpoint(new Subscriber(true), b => b.When(async(session, ctx) =>
            {
                await session.Subscribe <MyEvent>();
                ctx.Instance2SubscribedNative = true;
            }))
                          .Done(c => c.EventReceived >= 1)
                          .Run();

            Assert.AreEqual(1, context.EventReceived);
        }
 public Subscriber()
 {
     EndpointSetup(new CustomizedServer(supportsNativeDelayedDelivery: true, supportsPublishSubscribe: false), (c, rd) =>
     {
         c.GetSettings().GetOrCreate <Publishers>().AddOrReplacePublishers("LegacyConfig", new List <PublisherTableEntry>
         {
             new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(PublisherEndpoint))
         });
         c.DisableFeature <AutoSubscribe>();
     });
 }
            protected override void Setup(FeatureConfigurationContext context)
            {
                var publishers       = context.Settings.Get <Publishers>();
                var publisherAddress = PublisherAddress.CreateFromEndpointName("PublisherEndpoint");

                publishers.AddOrReplacePublishers("MySource",
                                                  new List <PublisherTableEntry>
                {
                    new PublisherTableEntry(typeof(MyEvent), publisherAddress)
                });
            }
        public void Without_best_practice_enforcement_it_throws_if_specified_assembly_contains_only_commands()
        {
            //Enforce artificial conventions to make sure the is a single command (but no messages) in an assembly
            var conventionBuilder = new ConventionsBuilder(new SettingsHolder());

            conventionBuilder.DefiningCommandsAs(t => t == typeof(string));


            var source = new AssemblyPublisherSource(typeof(string).Assembly, PublisherAddress.CreateFromEndpointName("Destination"));

            Assert.That(() => source.GenerateWithoutBestPracticeEnforcement(conventionBuilder.Conventions).ToArray(), Throws.Exception.Message.Contains("Cannot configure publisher for assembly"));
        }
 public Subscriber()
 {
     EndpointSetup(new CustomizedServer(ConnectionString, false), (c, sd) =>
     {
         //SqlServerTransport no longer implements message-driven pub sub interface so we need to configure Publishers "manually"
         c.GetSettings().GetOrCreate<Publishers>().AddOrReplacePublishers("LegacyConfig", new List<PublisherTableEntry>
         {
             new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(PublisherEndpoint))
         });
         c.DisableFeature<AutoSubscribe>();
     });
 }
 public Subscriber()
 {
     EndpointSetup <DefaultServer>(c =>
     {
         c.DisableFeature <AutoSubscribe>();
         c.GetSettings().GetOrCreate <Publishers>()
         .AddOrReplacePublishers("CustomRoutingFeature", new List <PublisherTableEntry>
         {
             new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(PublisherEndpoint))
         });
     });
 }
Ejemplo n.º 9
0
 public Subscriber()
 {
     EndpointSetup <DefaultServer>(c =>
     {
         c.GetSettings().Set("SqlServer.DisableNativePubSub", true);
         //SqlServerTransport no longer implements message-driven pub sub interface so we need to configure Publishers "manually"
         c.GetSettings().GetOrCreate <Publishers>().AddOrReplacePublishers("LegacyConfig", new List <PublisherTableEntry>
         {
             new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(PublisherEndpoint))
         });
         c.DisableFeature <AutoSubscribe>();
     });
 }
Ejemplo n.º 10
0
        public void When_group_does_not_exist_should_add_routes()
        {
            var publisherTable = new Publishers();
            var publisher      = PublisherAddress.CreateFromEndpointName("Endpoint1");

            publisherTable.AddOrReplacePublishers("key", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), publisher),
            });

            var retrievedPublisher = publisherTable.GetPublisherFor(typeof(MyEvent)).Single();

            Assert.AreSame(publisher, retrievedPublisher);
        }
Ejemplo n.º 11
0
        public void When_multiple_publishers_exist_should_return_all_of_them()
        {
            var publisherTable = new Publishers();

            var pub1 = PublisherAddress.CreateFromEndpointName("Endpoint1");
            var pub2 = PublisherAddress.CreateFromEndpointName("Endpoint2");

            publisherTable.AddOrReplacePublishers("key2", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), pub1),
            });
            publisherTable.AddOrReplacePublishers("key1", new List <PublisherTableEntry>
            {
                new PublisherTableEntry(typeof(MyEvent), pub2),
            });

            var pubs = publisherTable.GetPublisherFor(typeof(MyEvent)).ToArray();

            Assert.Contains(pub1, pubs);
            Assert.Contains(pub2, pubs);
        }
Ejemplo n.º 12
0
    protected override void Setup(FeatureConfigurationContext context)
    {
        var exchangeEndpointName = context.Settings.Get <string>(TopicExchangeEndpointNameKey);

        var transportInfrastructure = context.Settings.Get <TransportInfrastructure>();
        var conventions             = context.Settings.Get <Conventions>();
        var publishers         = context.Settings.Get <Publishers>();
        var endpointInstances  = context.Settings.Get <EndpointInstances>();
        var distributionPolicy = context.Settings.Get <DistributionPolicy>();

        var topicExchangeAddressManager = new TopicExchangeAddressManager(
            exchangeEndpointName,
            endpointInstances,
            i => transportInfrastructure.ToTransportAddress(LogicalAddress.CreateRemoteAddress(i)),
            distributionPolicy
            );

        var eventTypes = context.Settings.GetAvailableTypes().Where(conventions.IsEventType).ToArray();

        // Route all Subscription requests to the TopicExchange
        publishers.AddOrReplacePublishers(
            "TopicExchange",
            eventTypes.Select(
                e => new PublisherTableEntry(e, PublisherAddress.CreateFromEndpointName(exchangeEndpointName))
                ).ToList()
            );

        // Route a copy of all published events to the TopicExchange
        context.RegisterStartupTask(b => new SubscribeTopicExchangeToAllEvents(
                                        eventTypes,
                                        b.Build <ISubscriptionStorage>(),
                                        topicExchangeAddressManager
                                        ));

        // Forward all incoming Subscribe/Unsubscribe requests from legacy subscribers to the topic exchange
        context.Pipeline.Replace(
            "ProcessSubscriptionRequests",
            builder => new RerouteIncomingPubSubMessagesToTopicExchange(topicExchangeAddressManager),
            "Reroutes incoming Subscribe and Unsubscribe messages to the topic exchange");
    }
        /// <summary>
        /// Registers a publisher endpoint for a given event type.
        /// </summary>
        /// <param name="eventType">The event type.</param>
        /// <param name="publisherEndpoint">The publisher endpoint.</param>
        public void RegisterPublisher(Type eventType, string publisherEndpoint)
        {
            Guard.AgainstNullAndEmpty(nameof(publisherEndpoint), publisherEndpoint);

            ThrowOnAddress(publisherEndpoint);
            Settings.GetOrCreate <ConfiguredPublishers>().Add(new TypePublisherSource(eventType, PublisherAddress.CreateFromEndpointName(publisherEndpoint)));
        }
Ejemplo n.º 14
0
        public void Without_best_practice_enforcement_it_throws_if_specified_type_is_not_a_message()
        {
            var source = new TypePublisherSource(typeof(NonMessage), PublisherAddress.CreateFromEndpointName("Destination"));

            Assert.That(() => source.GenerateWithoutBestPracticeEnforcement(new Conventions()).ToArray(), Throws.Exception.Message.Contains("it is not considered a message"));
        }
Ejemplo n.º 15
0
        public void Without_best_practice_enforcement_it_throws_if_specified_type_is_a_command()
        {
            var source = new TypePublisherSource(typeof(Command), PublisherAddress.CreateFromEndpointName("Destination"));

            Assert.That(() => source.GenerateWithoutBestPracticeEnforcement(new Conventions()).ToArray(), Throws.Exception.Message.Contains("because it is a command"));
        }
        /// <summary>
        /// Registers a publisher endpoint for a given event type.
        /// </summary>
        /// <param name="routingSettings">The <see cref="RoutingSettings&lt;T&gt;" /> to extend.</param>
        /// <param name="eventType">The event type.</param>
        /// <param name="publisherEndpoint">The publisher endpoint.</param>
        public static void RegisterPublisher <T>(this RoutingSettings <T> routingSettings, Type eventType, string publisherEndpoint) where T : TransportDefinition, IMessageDrivenSubscriptionTransport
        {
            Guard.AgainstNullAndEmpty(nameof(publisherEndpoint), publisherEndpoint);

            ThrowOnAddress(publisherEndpoint);
            routingSettings.Settings.GetOrCreate <ConfiguredPublishers>().Add(new TypePublisherSource(eventType, PublisherAddress.CreateFromEndpointName(publisherEndpoint)));
        }
        /// <summary>
        /// Registers a publisher endpoint for all event types in a given assembly and namespace.
        /// </summary>
        /// <param name="routingSettings">The <see cref="RoutingSettings&lt;T&gt;" /> to extend.</param>
        /// <param name="assembly">The assembly containing the event types.</param>
        /// <param name="namespace"> The namespace containing the event types. The given value must exactly match the target namespace.</param>
        /// <param name="publisherEndpoint">The publisher endpoint.</param>
        public static void RegisterPublisher <T>(this RoutingSettings <T> routingSettings, Assembly assembly, string @namespace, string publisherEndpoint) where T : TransportDefinition, IMessageDrivenSubscriptionTransport
        {
            Guard.AgainstNull(nameof(assembly), assembly);
            Guard.AgainstNullAndEmpty(nameof(publisherEndpoint), publisherEndpoint);

            ThrowOnAddress(publisherEndpoint);

            // empty namespace is null, not string.empty
            @namespace = @namespace == string.Empty ? null : @namespace;

            routingSettings.Settings.GetOrCreate <ConfiguredPublishers>().Add(new NamespacePublisherSource(assembly, @namespace, PublisherAddress.CreateFromEndpointName(publisherEndpoint)));
        }
        public void It_throws_if_specified_assembly_contains_no_message_types()
        {
            var source = new AssemblyPublisherSource(typeof(string).Assembly, PublisherAddress.CreateFromEndpointName("Destination"));

            Assert.That(() => source.GenerateWithBestPracticeEnforcement(new Conventions()).ToArray(), Throws.Exception.Message.Contains("Cannot configure publisher for assembly"));
        }
        public void It_returns_only_event_types()
        {
            var source = new AssemblyPublisherSource(Assembly.GetExecutingAssembly(), PublisherAddress.CreateFromEndpointName("Destination"));
            var routes = source.GenerateWithBestPracticeEnforcement(new Conventions()).ToArray();

            Assert.IsFalse(routes.Any(r => r.EventType == typeof(NonMessage)));
            Assert.IsFalse(routes.Any(r => r.EventType == typeof(NonEvent)));
        }
        public void It_returns_only_types_from_specified_namespace()
        {
            var source      = new NamespacePublisherSource(Assembly.GetExecutingAssembly(), "NServiceBus.Core.Tests.Routing.NamespacePublisherSourceTest", PublisherAddress.CreateFromEndpointName("Destination"));
            var routes      = source.GenerateWithBestPracticeEnforcement(new Conventions());
            var routedTypes = routes.Select(r => r.EventType).ToArray();

            CollectionAssert.Contains(routedTypes, typeof(Event));
            CollectionAssert.DoesNotContain(routedTypes, typeof(ExcludedEvent));
        }
        public async Task Should_not_lose_any_events()
        {
            var subscriptionStorage = new TestingInMemorySubscriptionStorage();

            //Before migration begins
            var beforeMigration = await Scenario.Define <Context>()
                                  .WithEndpoint(new Publisher(supportsPublishSubscribe: false), b =>
            {
                b.CustomConfig(c =>
                {
                    c.UsePersistence <TestingInMemoryPersistence, StorageType.Subscriptions>().UseStorage(subscriptionStorage);
                });
                b.When(c => c.SubscribedMessageDriven, (session, ctx) => session.Publish(new MyEvent()));
            })

                                  .WithEndpoint(new Subscriber(supportsPublishSubscribe: false), b =>
            {
                b.CustomConfig(c =>
                {
                    c.GetSettings().GetOrCreate <Publishers>().AddOrReplacePublishers("LegacyConfig", new List <PublisherTableEntry>
                    {
                        new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(PublisherEndpoint))
                    });
                });
                b.When(async(session, ctx) =>
                {
                    await session.Subscribe <MyEvent>();
                });
            })
                                  .Done(c => c.GotTheEvent)
                                  .Run(TimeSpan.FromSeconds(30));

            Assert.True(beforeMigration.GotTheEvent);

            //Subscriber migrated and in compatibility mode.
            var subscriberMigratedRunSettings = new RunSettings
            {
                TestExecutionTimeout = TimeSpan.FromSeconds(30)
            };
            var subscriberMigrated = await Scenario.Define <Context>()
                                     .WithEndpoint(new Publisher(supportsPublishSubscribe: false), b =>
            {
                b.CustomConfig(c =>
                {
                    c.UsePersistence <TestingInMemoryPersistence, StorageType.Subscriptions>().UseStorage(subscriptionStorage);
                });
                b.When(c => c.SubscribedMessageDriven, (session, ctx) => session.Publish(new MyEvent()));
            })

                                     .WithEndpoint(new Subscriber(supportsPublishSubscribe: true), b =>
            {
                b.CustomConfig(c =>
                {
                    var compatModeSettings = c.ConfigureRouting().EnableMessageDrivenPubSubCompatibilityMode();
                    compatModeSettings.RegisterPublisher(typeof(MyEvent), PublisherEndpoint);
                });
                b.When(async(session, ctx) =>
                {
                    //Subscribes both using native feature and message-driven
                    await session.Subscribe <MyEvent>();
                    ctx.SubscribedNative = true;
                });
            })
                                     .Done(c => c.GotTheEvent && c.SubscribedNative) //we ensure the subscriber did subscriber with the native mechanism
                                     .Run(subscriberMigratedRunSettings);

            Assert.True(subscriberMigrated.GotTheEvent);

            //Publisher migrated and in compatibility mode
            var publisherMigratedRunSettings = new RunSettings
            {
                TestExecutionTimeout = TimeSpan.FromSeconds(30)
            };
            var publisherMigrated = await Scenario.Define <Context>()
                                    .WithEndpoint(new Publisher(supportsPublishSubscribe: true), b =>
            {
                b.CustomConfig(c =>
                {
                    c.UsePersistence <TestingInMemoryPersistence, StorageType.Subscriptions>().UseStorage(subscriptionStorage);
                    c.ConfigureRouting().EnableMessageDrivenPubSubCompatibilityMode();
                });
                b.When(c => c.SubscribedMessageDriven && c.SubscribedNative, (session, ctx) => session.Publish(new MyEvent()));
            })

                                    .WithEndpoint(new Subscriber(supportsPublishSubscribe: true), b =>
            {
                b.CustomConfig(c =>
                {
                    var compatModeSettings = c.ConfigureRouting().EnableMessageDrivenPubSubCompatibilityMode();
                    // not needed but left here to enforce duplicates
                    compatModeSettings.RegisterPublisher(typeof(MyEvent), PublisherEndpoint);
                });
                b.When(async(session, ctx) =>
                {
                    await session.Subscribe <MyEvent>();
                    ctx.SubscribedNative = true;
                });
            })
                                    .Done(c => c.GotTheEvent)
                                    .Run(publisherMigratedRunSettings);

            Assert.True(publisherMigrated.GotTheEvent);

            //Compatibility mode disabled in both publisher and subscriber
            var compatModeDisabled = await Scenario.Define <Context>()
                                     .WithEndpoint(new Publisher(supportsPublishSubscribe: true), b =>
            {
                b.When(c => c.EndpointsStarted, (session, ctx) => session.Publish(new MyEvent()));
            })
                                     .WithEndpoint(new Subscriber(supportsPublishSubscribe: true), c => { })
                                     .Done(c => c.GotTheEvent)
                                     .Run(TimeSpan.FromSeconds(30));

            Assert.True(compatModeDisabled.GotTheEvent);
        }
        /// <summary>
        /// Registers a publisher endpoint for all event types in a given assembly and namespace.
        /// </summary>
        /// <param name="assembly">The assembly containing the event types.</param>
        /// <param name="namespace"> The namespace containing the event types. The given value must exactly match the target namespace.</param>
        /// <param name="publisherEndpoint">The publisher endpoint.</param>
        public void RegisterPublisher(Assembly assembly, string @namespace, string publisherEndpoint)
        {
            Guard.AgainstNull(nameof(assembly), assembly);
            Guard.AgainstNullAndEmpty(nameof(publisherEndpoint), publisherEndpoint);

            ThrowOnAddress(publisherEndpoint);

            // empty namespace is null, not string.empty
            @namespace = @namespace == string.Empty ? null : @namespace;

            Settings.GetOrCreate <ConfiguredPublishers>().Add(new NamespacePublisherSource(assembly, @namespace, PublisherAddress.CreateFromEndpointName(publisherEndpoint)));
        }
        public void It_matches_namespace_in_case_insensitive_way()
        {
            var source      = new NamespacePublisherSource(Assembly.GetExecutingAssembly(), "NServiceBus.Core.Tests.Routing.NAMESPACEpublisherSOURCEtest", PublisherAddress.CreateFromEndpointName("Destination"));
            var routes      = source.GenerateWithBestPracticeEnforcement(new Conventions()).ToArray();
            var routedTypes = routes.Select(r => r.EventType);

            CollectionAssert.Contains(routedTypes, typeof(Event));
        }
        public void Without_best_practice_enforcement_it_throws_if_specified_assembly_contains_only_commands()
        {
            var source = new NamespacePublisherSource(Assembly.GetExecutingAssembly(), "NServiceBus.Core.Tests.Routing.NamespacePublisherSourceTest.Commands", PublisherAddress.CreateFromEndpointName("Destination"));

            Assert.That(() => source.GenerateWithoutBestPracticeEnforcement(new Conventions()).ToArray(), Throws.Exception.Message.Contains("Cannot configure publisher for namespace"));
        }
Ejemplo n.º 25
0
        public async Task Should_not_lose_any_events()
        {
            var subscriptionStorage = new TestingInMemorySubscriptionStorage();

            //Before migration begins
            var beforeMigration = await Scenario.Define <Context>()
                                  .WithEndpoint <Publisher>(b =>
            {
                b.CustomConfig(c =>
                {
                    c.UsePersistence <TestingInMemoryPersistence, StorageType.Subscriptions>().UseStorage(subscriptionStorage);
                    c.GetSettings().Set("SqlServer.DisableNativePubSub", true);
                });
                b.When(c => c.SubscribedMessageDriven, (session, ctx) => session.Publish(new MyEvent()));
            })

                                  .WithEndpoint <Subscriber>(b =>
            {
                b.CustomConfig(c =>
                {
                    c.GetSettings().Set("SqlServer.DisableNativePubSub", true);
                    c.GetSettings().GetOrCreate <Publishers>().AddOrReplacePublishers("LegacyConfig", new List <PublisherTableEntry>
                    {
                        new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(PublisherEndpoint))
                    });
                });
                b.When(async(session, ctx) =>
                {
                    await session.Subscribe <MyEvent>();
                });
            })
                                  .Done(c => c.GotTheEvent)
                                  .Run(TimeSpan.FromSeconds(30));

            Assert.True(beforeMigration.GotTheEvent);

            //Publisher migrated and in compatibility mode
            var publisherMigrated = await Scenario.Define <Context>()
                                    .WithEndpoint <Publisher>(b =>
            {
                b.CustomConfig(c =>
                {
                    c.UsePersistence <TestingInMemoryPersistence, StorageType.Subscriptions>().UseStorage(subscriptionStorage);
                    c.GetSettings().Set("NServiceBus.Subscriptions.EnableMigrationMode", true);
                });
                b.When(c => c.EndpointsStarted, (session, ctx) => session.Publish(new MyEvent()));
            })

                                    .WithEndpoint <Subscriber>(b =>
            {
                b.CustomConfig(c =>
                {
                    c.GetSettings().Set("SqlServer.DisableNativePubSub", true);
                    c.GetSettings().GetOrCreate <Publishers>().AddOrReplacePublishers("LegacyConfig", new List <PublisherTableEntry>
                    {
                        new PublisherTableEntry(typeof(MyEvent), PublisherAddress.CreateFromEndpointName(PublisherEndpoint))
                    });
                });
                b.When(async(session, ctx) =>
                {
                    await session.Subscribe <MyEvent>();
                });
            })
                                    .Done(c => c.GotTheEvent)
                                    .Run(TimeSpan.FromSeconds(30));

            Assert.True(publisherMigrated.GotTheEvent);

            //Subscriber migrated and in compatibility mode
            var subscriberMigratedRunSettings = new RunSettings
            {
                TestExecutionTimeout = TimeSpan.FromSeconds(30)
            };

            subscriberMigratedRunSettings.Set("DoNotCleanNativeSubscriptions", true);
            var subscriberMigrated = await Scenario.Define <Context>()
                                     .WithEndpoint <Publisher>(b =>
            {
                b.CustomConfig(c =>
                {
                    c.UsePersistence <TestingInMemoryPersistence, StorageType.Subscriptions>().UseStorage(subscriptionStorage);
                    c.GetSettings().Set("NServiceBus.Subscriptions.EnableMigrationMode", true);
                });
                b.When(c => c.SubscribedMessageDriven && c.SubscribedNative, (session, ctx) => session.Publish(new MyEvent()));
            })

                                     .WithEndpoint <Subscriber>(b =>
            {
                b.CustomConfig(c =>
                {
                    c.GetSettings().Set("NServiceBus.Subscriptions.EnableMigrationMode", true);
                    var compatModeSettings = new SubscriptionMigrationModeSettings(c.GetSettings());
                    compatModeSettings.RegisterPublisher(typeof(MyEvent), PublisherEndpoint);
                });
                b.When(async(session, ctx) =>
                {
                    //Subscribes both using native feature and message-driven
                    await session.Subscribe <MyEvent>();
                    ctx.SubscribedNative = true;
                });
            })
                                     .Done(c => c.GotTheEvent)
                                     .Run(subscriberMigratedRunSettings);

            Assert.True(subscriberMigrated.GotTheEvent);

            //Compatibility mode disabled in both publisher and subscriber
            var compatModeDisabled = await Scenario.Define <Context>()
                                     .WithEndpoint <Publisher>(b =>
            {
                b.When(c => c.EndpointsStarted, (session, ctx) => session.Publish(new MyEvent()));
            })
                                     .WithEndpoint <Subscriber>()
                                     .Done(c => c.GotTheEvent)
                                     .Run(TimeSpan.FromSeconds(30));

            Assert.True(compatModeDisabled.GotTheEvent);
        }
        /// <summary>
        /// Registers a publisher endpoint for all event types in a given assembly.
        /// </summary>
        /// <param name="assembly">The assembly containing the event types.</param>
        /// <param name="publisherEndpoint">The publisher endpoint.</param>
        public void RegisterPublisher(Assembly assembly, string publisherEndpoint)
        {
            Guard.AgainstNull(nameof(assembly), assembly);
            Guard.AgainstNullAndEmpty(nameof(publisherEndpoint), publisherEndpoint);

            ThrowOnAddress(publisherEndpoint);

            Settings.GetOrCreate <ConfiguredPublishers>().Add(new AssemblyPublisherSource(assembly, PublisherAddress.CreateFromEndpointName(publisherEndpoint)));
        }