Exemple #1
0
        public async Task use_fan_out_exchange()
        {
            var exchangeName = "fanout";
            var queueName1   = "messages12";
            var queueName2   = "messages13";
            var queueName3   = "messages14";


            var publisher = JasperHost.For(_ =>
            {
                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareExchange(exchangeName, ex => ex.ExchangeType = ExchangeType.Fanout);
                    x.DeclareQueue(queueName1);
                    x.DeclareQueue(queueName2);
                    x.DeclareQueue(queueName3);
                    x.DeclareBinding(new Binding
                    {
                        BindingKey   = "key1",
                        QueueName    = queueName1,
                        ExchangeName = exchangeName
                    });

                    x.DeclareBinding(new Binding
                    {
                        BindingKey   = "key1",
                        QueueName    = queueName2,
                        ExchangeName = exchangeName
                    });

                    x.DeclareBinding(new Binding
                    {
                        BindingKey   = "key1",
                        QueueName    = queueName3,
                        ExchangeName = exchangeName
                    });

                    x.AutoProvision = true;
                });

                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.PublishAllMessages().ToRabbitExchange("fanout");
            });

            var receiver1 = JasperHost.For(_ =>
            {
                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                });



                _.Extensions.UseMessageTrackingTestingSupport();
                _.Endpoints.ListenToRabbitQueue(queueName1);
                _.Services.AddSingleton <ColorHistory>();
            });

            var receiver2 = JasperHost.For(_ =>
            {
                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                });


                _.Extensions.UseMessageTrackingTestingSupport();
                _.Endpoints.ListenToRabbitQueue(queueName2);
                _.Services.AddSingleton <ColorHistory>();
            });

            var receiver3 = JasperHost.For(_ =>
            {
                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                });


                _.Extensions.UseMessageTrackingTestingSupport();
                _.Endpoints.ListenToRabbitQueue(queueName3);

                _.Services.AddSingleton <ColorHistory>();
            });


            try
            {
                var session = await publisher
                              .TrackActivity()
                              .AlsoTrack(receiver1, receiver2, receiver3)
                              .WaitForMessageToBeReceivedAt <ColorChosen>(receiver1)
                              .WaitForMessageToBeReceivedAt <ColorChosen>(receiver2)
                              .WaitForMessageToBeReceivedAt <ColorChosen>(receiver3)
                              .SendMessageAndWait(new ColorChosen {
                    Name = "Purple"
                });


                receiver1.Get <ColorHistory>().Name.ShouldBe("Purple");
                receiver2.Get <ColorHistory>().Name.ShouldBe("Purple");
                receiver3.Get <ColorHistory>().Name.ShouldBe("Purple");
            }
            finally
            {
                publisher.Dispose();
                receiver1.Dispose();
                receiver2.Dispose();
                receiver3.Dispose();
            }
        }
Exemple #2
0
        public async Task send_message_to_and_receive_through_rabbitmq_with_routing_key()
        {
            var queueName    = "messages5";
            var exchangeName = "exchange1";

            var publisher = JasperHost.For(_ =>
            {
                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareQueue(queueName);
                    x.DeclareExchange(exchangeName);
                    x.DeclareBinding(new Binding
                    {
                        ExchangeName = exchangeName,
                        BindingKey   = "key2",
                        QueueName    = queueName
                    });

                    x.AutoProvision = true;
                });

                _.Endpoints.PublishAllMessages().ToRabbit("key2", exchangeName);
            });

            var receiver = JasperHost.For(_ =>
            {
                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareQueue("messages5");
                    x.DeclareExchange(exchangeName);
                    x.DeclareBinding(new Binding
                    {
                        ExchangeName = exchangeName,
                        BindingKey   = "key2",
                        QueueName    = queueName
                    });

                    x.AutoProvision = true;
                });

                _.Services.AddSingleton <ColorHistory>();

                _.Endpoints.ListenToRabbitQueue(queueName);
            });

            try
            {
                await publisher
                .TrackActivity()
                .AlsoTrack(receiver)
                .SendMessageAndWait(new ColorChosen {
                    Name = "Orange"
                });

                receiver.Get <ColorHistory>().Name.ShouldBe("Orange");
            }
            finally
            {
                publisher.Dispose();
                receiver.Dispose();
            }
        }
Exemple #3
0
        public async Task schedule_send_message_to_and_receive_through_rabbitmq_with_durable_transport_option()
        {
            var uri = "rabbitmq://default/messages11/durable";

            var publisher = JasperHost.For(_ =>
            {
                _.Advanced.ScheduledJobFirstExecution = 1.Seconds();
                _.Advanced.ScheduledJobPollingTime    = 1.Seconds();
                _.ServiceName = "Publisher";

                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareQueue("messages11");


                    x.AutoProvision = true;
                });


                _.Endpoints.PublishAllMessages().ToRabbit("messages11").Durably();



                _.Extensions.UseMarten(x =>
                {
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                    x.DatabaseSchemaName      = "rabbit_sender";
                });
            });

            publisher.RebuildMessageStorage();

            var receiver = JasperHost.For(_ =>
            {
                _.ServiceName = "Receiver";

                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                });



                _.Endpoints.ListenToRabbitQueue("messages11");
                _.Services.AddSingleton <ColorHistory>();

                _.Extensions.UseMarten(x =>
                {
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                    x.DatabaseSchemaName      = "rabbit_receiver";
                });
            });

            receiver.RebuildMessageStorage();



            try
            {
                await publisher
                .TrackActivity()
                .AlsoTrack(receiver)
                .WaitForMessageToBeReceivedAt <ColorChosen>(receiver)
                .Timeout(15.Seconds())
                .ExecuteAndWait(c => c.ScheduleSend(new ColorChosen {
                    Name = "Orange"
                }, 5.Seconds()));

                receiver.Get <ColorHistory>().Name.ShouldBe("Orange");
            }
            finally
            {
                publisher.Dispose();
                receiver.Dispose();
            }
        }
 protected void StartTheSender(Action <JasperRegistry> configure)
 {
     configure(senderRegistry);
     theSender = JasperHost.For(senderRegistry);
 }
Exemple #5
0
        public async Task reply_uri_mechanics()
        {
            var publisher = JasperHost.For(_ =>
            {
                _.ServiceName = "Publisher";
                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareQueue("messages20");
                    x.DeclareQueue("messages21");
                    x.AutoProvision = true;
                });

                _.Endpoints
                .PublishAllMessages()
                .ToRabbit("messages20")
                .Durably();

                _.Endpoints.ListenToRabbitQueue("messages21").UseForReplies();

                _.Extensions.UseMarten(x =>
                {
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                    x.DatabaseSchemaName      = "sender";
                });

                _.Advanced.StorageProvisioning = StorageProvisioning.Rebuild;
            });

            var receiver = JasperHost.For(_ =>
            {
                _.ServiceName = "Receiver";

                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareQueue("messages20");
                    x.AutoProvision = true;
                });

                _.Endpoints.ListenToRabbitQueue("messages20");
                _.Services.AddSingleton <ColorHistory>();

                _.Extensions.UseMarten(x =>
                {
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                    x.DatabaseSchemaName      = "receiver";
                });

                _.Advanced.StorageProvisioning = StorageProvisioning.Rebuild;
            });


            try
            {
                var session = await publisher
                              .TrackActivity()
                              .AlsoTrack(receiver)
                              .SendMessageAndWait(new PingMessage {
                    Number = 1
                });


                // TODO -- let's make an assertion here?
                var records = session.FindEnvelopesWithMessageType <PongMessage>(EventType.Received);
                records.Any(x => x.ServiceName == "Publisher").ShouldBeTrue();
            }
            finally
            {
                publisher.Dispose();
                receiver.Dispose();
            }
        }
Exemple #6
0
        public async Task use_fan_out_exchange()
        {
            var uri = "rabbitmq://localhost/queue/messages";

            var publisher = JasperHost.For(_ =>
            {
                _.Settings.ConfigureRabbitMq(settings =>
                {
                    settings.Connections.Add("localhost", "host=localhost;ExchangeType=fanout;ExchangeName=north");
                });

                _.Publish.AllMessagesTo(uri);

                _.HttpRoutes.DisableConventionalDiscovery();
            });

            var receiver1 = JasperHost.For(_ =>
            {
                _.Settings.ConfigureRabbitMq(settings =>
                {
                    settings.Connections.Add("localhost", "host=localhost;ExchangeType=fanout;ExchangeName=north");
                });

                _.Transports.ListenForMessagesFrom(uri);
                _.Services.AddSingleton <ColorHistory>();
                _.Services.AddSingleton <MessageTracker>();

                _.HttpRoutes.DisableConventionalDiscovery();
            });

            var receiver2 = JasperHost.For(_ =>
            {
                _.Settings.ConfigureRabbitMq(settings =>
                {
                    settings.Connections.Add("localhost", "host=localhost;ExchangeType=fanout;ExchangeName=north");
                });

                _.Transports.ListenForMessagesFrom(uri);
                _.Services.AddSingleton <ColorHistory>();
                _.Services.AddSingleton <MessageTracker>();

                _.HttpRoutes.DisableConventionalDiscovery();
            });

            var receiver3 = JasperHost.For(_ =>
            {
                _.Settings.ConfigureRabbitMq(settings =>
                {
                    settings.Connections.Add("localhost", "host=localhost;ExchangeType=fanout;ExchangeName=north");
                });

                _.Transports.ListenForMessagesFrom(uri);
                _.Services.AddSingleton <ColorHistory>();
                _.Services.AddSingleton <MessageTracker>();

                _.HttpRoutes.DisableConventionalDiscovery();
            });

            var wait1 = receiver1.Get <MessageTracker>().WaitFor <ColorChosen>();
            var wait2 = receiver2.Get <MessageTracker>().WaitFor <ColorChosen>();
            var wait3 = receiver3.Get <MessageTracker>().WaitFor <ColorChosen>();

            try
            {
                await publisher.Messaging.Send(new ColorChosen { Name = "Purple" });

                await wait1;
                //await wait2;
                //await wait3;

                receiver1.Get <ColorHistory>().Name.ShouldBe("Purple");
                //receiver2.Get<ColorHistory>().Name.ShouldBe("Purple");
                //receiver3.Get<ColorHistory>().Name.ShouldBe("Purple");
            }
            finally
            {
                publisher.Dispose();
                receiver1.Dispose();
                receiver2.Dispose();
                receiver3.Dispose();
            }
        }
 public InvokeBenchmark()
 {
     _host = JasperHost.For <Sender1>();
 }
 public PingPongBenchmark()
 {
     _receiving = JasperHost.For <Receiver1>();
     _sender    = JasperHost.For <Sender1>();
 }
 public void SenderIs <T>() where T : JasperOptions, new()
 {
     theSender = JasperHost.For <T>(configureSender);
 }
Exemple #10
0
 protected void StartTheReceiver(Action <JasperOptions> configure)
 {
     configure(receiverOptions);
     theReceiver = JasperHost.For(receiverOptions);
 }
Exemple #11
0
 protected void RestartTheReceiver()
 {
     theSender = JasperHost.For(receiverOptions);
 }
Exemple #12
0
 protected void StartTheSender(Action <JasperOptions> configure)
 {
     configure(senderOptions);
     theSender = JasperHost.For(senderOptions);
 }
 protected void RestartTheReceiver()
 {
     theSender = JasperHost.For(receiverRegistry);
 }
 protected void StartTheReceiver(Action <JasperRegistry> configure)
 {
     configure(receiverRegistry);
     theReceiver = JasperHost.For(receiverRegistry);
 }
Exemple #15
0
        public async Task send_message_to_and_receive_through_rabbitmq_with_durable_transport_option()
        {
            var publisher = JasperHost.For(_ =>
            {
                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareQueue("messages2");
                    x.AutoProvision = true;
                });

                _.Endpoints
                .PublishAllMessages()
                .ToRabbit("messages2")
                .Durably();

                _.Extensions.UseMarten(x =>
                {
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                    x.DatabaseSchemaName      = "sender";
                });

                _.Advanced.StorageProvisioning = StorageProvisioning.Rebuild;
            });

            var receiver = JasperHost.For(_ =>
            {
                _.Extensions.UseMessageTrackingTestingSupport();

                _.Endpoints.ConfigureRabbitMq(x =>
                {
                    x.ConnectionFactory.HostName = "localhost";
                    x.DeclareQueue("messages2");
                    x.AutoProvision = true;
                });

                _.Endpoints.ListenToRabbitQueue("messages2");
                _.Services.AddSingleton <ColorHistory>();

                _.Extensions.UseMarten(x =>
                {
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                    x.DatabaseSchemaName      = "receiver";
                });

                _.Advanced.StorageProvisioning = StorageProvisioning.Rebuild;
            });


            try
            {
                await publisher
                .TrackActivity()
                .AlsoTrack(receiver)
                .SendMessageAndWait(new ColorChosen {
                    Name = "Orange"
                });


                receiver.Get <ColorHistory>().Name.ShouldBe("Orange");
            }
            finally
            {
                publisher.Dispose();
                receiver.Dispose();
            }
        }
Exemple #16
0
 public void SenderIs(JasperOptions options)
 {
     configureSender(options);
     theSender = JasperHost.For(options);
 }
Exemple #17
0
        public async Task schedule_send_message_to_and_receive_through_rabbitmq_with_durable_transport_option()
        {
            var uri = "rabbitmq://localhost:5672/durable/queue/messages11";

            var publisher = JasperHost.For(_ =>
            {
                _.Settings.AddRabbitMqHost("localhost");

                _.HttpRoutes.DisableConventionalDiscovery();

                _.Publish.AllMessagesTo(uri);

                _.Include <MartenBackedPersistence>();

                _.Settings.ConfigureMarten(x =>
                {
                    x.DatabaseSchemaName = "rabbit_sender";
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                });
            });

            publisher.RebuildMessageStorage();

            var receiver = JasperHost.For(_ =>
            {
                _.Settings.AddRabbitMqHost("localhost");

                _.HttpRoutes.DisableConventionalDiscovery();

                _.Transports.ListenForMessagesFrom(uri);
                _.Services.AddSingleton <ColorHistory>();
                _.Services.AddSingleton <MessageTracker>();

                _.Include <MartenBackedPersistence>();

                _.Settings.ConfigureMarten(x =>
                {
                    x.DatabaseSchemaName = "rabbit_receiver";
                    x.Connection(Servers.PostgresConnectionString);
                    x.AutoCreateSchemaObjects = AutoCreate.All;
                });
            });

            receiver.RebuildMessageStorage();

            var wait = receiver.Get <MessageTracker>().WaitFor <ColorChosen>();

            try
            {
                await publisher.Messaging.ScheduleSend(new ColorChosen { Name = "Orange" }, 5.Seconds());

                await wait;

                receiver.Get <ColorHistory>().Name.ShouldBe("Orange");
            }
            finally
            {
                publisher.Dispose();
                receiver.Dispose();
            }
        }
Exemple #18
0
 public void ReceiverIs <T>() where T : JasperOptions, new()
 {
     theReceiver = JasperHost.For <T>(configureReceiver);
 }
Exemple #19
0
        public MessageInvocationTests()
        {
            theHost = JasperHost.For <SampleApp>();

            theHost.Get <IDocumentStore>().Advanced.Clean.CompletelyRemoveAll();
        }
Exemple #20
0
 public void ReceiverIs(JasperOptions options)
 {
     configureReceiver(options);
     theReceiver = JasperHost.For(options);
 }
Exemple #21
0
 public code_generation()
 {
     runtime = JasperHost.For <MartenUsingApp>();
 }
 internal void Bootstrap(IMessageLogger logger)
 {
     _registry.Services.AddSingleton(logger);
     Runtime = JasperHost.For(_registry);
 }