public async Task Should_deliver_the_reply_without_the_need_to_configure_the_hub()
    {
        var result = await Scenario.Define <Context>()
                     .WithComponent(new SwitchComponent(() =>
        {
            var cfg = new SwitchConfiguration();
            cfg.AddPort <TestTransport>("Port1", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port2", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port3", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());

            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Sender1))] = "Port1";
            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Sender2))] = "Port2";
            //Sender3's port is configured manually in Sender2

            return(cfg);
        }))
                     .WithEndpoint <Sender1>(c => c.When(s => s.Send(new MyRequest())))
                     .WithEndpoint <Sender2>(c => c.When(s => s.Send(new MyRequest())))
                     .WithEndpoint <Sender3>(c => c.When(s => s.Send(new MyRequest())))
                     .Done(c => c.Response1Received && c.Response2Received && c.Response3Received)
                     .Run(TimeSpan.FromSeconds(20));

        Assert.IsTrue(result.Request1Received);
        Assert.IsTrue(result.Response1Received);
        Assert.IsTrue(result.Request2Received);
        Assert.IsTrue(result.Response2Received);
        Assert.IsTrue(result.Request3Received);
        Assert.IsTrue(result.Response3Received);
    }
    public void ThreeWaySwitch()
    {
        #region bridge-to-router-switch

        var switchConfig = new SwitchConfiguration();
        switchConfig.AddPort <RabbitMQTransport>("A", tx => tx.ConnectionString("host=a"));
        switchConfig.AddPort <RabbitMQTransport>("B", tx => tx.ConnectionString("host=b"));
        switchConfig.AddPort <RabbitMQTransport>("C", tx => tx.ConnectionString("host=c"));

        switchConfig.PortTable["MyEndpoint"]    = "A";
        switchConfig.PortTable["OtherEndpoint"] = "C";

        var @switch = Switch.Create(switchConfig);

        #endregion
    }
示例#3
0
    public async Task It_should_deliver_the_message_to_both_subscribers()
    {
        var result = await Scenario.Define <Context>()
                     .WithComponent(new SwitchComponent(() =>
        {
            var cfg = new SwitchConfiguration();
            cfg.AddPort <TestTransport>("Port1", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port2", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());
            cfg.AddPort <TestTransport>("Port3", t => { t.ConfigureNoNativePubSubBrokerA(); }).UseSubscriptionPersistence(new InMemorySubscriptionStorage());

            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Publisher))] = "Port1";
            return(cfg);
        }))
                     .WithEndpoint <Publisher>(c => c.When(x => x.BaseEventSubscribed && x.DerivedEventSubscribed, s => s.Publish(new MyDerivedEvent())))
                     .WithEndpoint <BaseEventSubscriber>()
                     .WithEndpoint <DerivedEventSubscriber>()
                     .Done(c => c.BaseEventDelivered && c.DerivedEventDeilvered)
                     .Run(TimeSpan.FromSeconds(20));

        Assert.IsTrue(result.BaseEventDelivered);
        Assert.IsTrue(result.DerivedEventDeilvered);
    }
示例#4
0
    public async Task It_should_deliver_the_message_to_both_subscribers()
    {
        var result = await Scenario.Define <Context>()
                     .WithComponent(new SwitchComponent(() =>
        {
            var cfg = new SwitchConfiguration();

            //Publisher - Broker B. Limit concurrency to ensure when tracer arrives the subscribe request has already been processed.
            cfg.AddPort <TestTransport>("Port1", t => t.ConfigureNativePubSubBrokerB()).LimitMessageProcessingConcurrencyTo(1);

            //BaseEventSubscriber - Broker A
            cfg.AddPort <TestTransport>("Port2", t => t.ConfigureNoNativePubSubBrokerA()).UseSubscriptionPersistence(new InMemorySubscriptionStorage());

            //DerivedEventSubscriber - Broker C`
            cfg.AddPort <TestTransport>("Port3", t => t.ConfigureNativePubSubBrokerC());

            cfg.PortTable[Conventions.EndpointNamingConvention(typeof(Publisher))] = "Port1";
            return(cfg);
        }))
                     .WithEndpoint <Publisher>(c => c.When(x => x.BaseEventSubscribed && x.DerivedEventSubscribed, s => s.Publish(new MyDerivedEvent3())))
                     .WithEndpoint <BaseEventSubscriber>(c => c.When(async s =>
        {
            await s.Subscribe <MyBaseEvent3>().ConfigureAwait(false);
            await s.Send(new TracerMessage()).ConfigureAwait(false);
        }))
                     .WithEndpoint <DerivedEventSubscriber>(c => c.When(async s =>
        {
            await s.Subscribe <MyDerivedEvent3>().ConfigureAwait(false);
            await s.Send(new TracerMessage()).ConfigureAwait(false);
        }))
                     .Done(c => c.BaseEventDelivered && c.DerivedEventDeilvered)
                     .Run();

        Assert.IsTrue(result.BaseEventDelivered);
        Assert.IsTrue(result.DerivedEventDeilvered);
    }
示例#5
0
    static async Task Main()
    {
        Console.Title = "Switch";

        var redSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(SwitchConnectionString), "Red", new SqlDialect.MsSqlServer(), null);
        await redSubscriptionStorage.Install().ConfigureAwait(false);

        var greenSubscriptionStorage = new SqlSubscriptionStorage(() => new SqlConnection(SwitchConnectionString), "Green", new SqlDialect.MsSqlServer(), null);
        await greenSubscriptionStorage.Install().ConfigureAwait(false);

        #region SwitchConfig

        var switchConfig = new SwitchConfiguration();

        var blueSubscriptionStorage = new SqlSubscriptionStorage(
            () => new SqlConnection(SwitchConnectionString),
            "Blue",
            new SqlDialect.MsSqlServer(),
            null);
        await blueSubscriptionStorage.Install().ConfigureAwait(false);

        switchConfig.AddPort <SqlServerTransport>("Blue", t =>
        {
            t.ConnectionString(ConnectionStrings.Blue);
        }).UseSubscriptionPersistence(blueSubscriptionStorage);


        switchConfig.AddPort <SqlServerTransport>("Red", t =>
        {
            t.ConnectionString(ConnectionStrings.Red);
        }).UseSubscriptionPersistence(redSubscriptionStorage);

        switchConfig.AddPort <SqlServerTransport>("Green", t =>
        {
            t.ConnectionString(ConnectionStrings.Green);
        }).UseSubscriptionPersistence(greenSubscriptionStorage);

        switchConfig.AutoCreateQueues();

        #endregion

        #region SwitchForwarding

        switchConfig.PortTable["Client"]   = "Blue";
        switchConfig.PortTable["Sales"]    = "Red";
        switchConfig.PortTable["Shipping"] = "Red";
        switchConfig.PortTable["Billing"]  = "Green";

        #endregion

        SqlHelper.EnsureDatabaseExists(SwitchConnectionString);
        SqlHelper.EnsureDatabaseExists(ConnectionStrings.Blue);
        SqlHelper.EnsureDatabaseExists(ConnectionStrings.Red);
        SqlHelper.EnsureDatabaseExists(ConnectionStrings.Green);

        var @switch = Switch.Create(switchConfig);

        await @switch.Start().ConfigureAwait(false);

        Console.WriteLine("Press <enter> to exit");
        Console.ReadLine();

        await @switch.Stop().ConfigureAwait(false);
    }