public async Task CanMoveMessageToErrorQueueEvenThoughExceptionIsNotSerializable()
        {
            using (var activator = new BuiltinHandlerActivator())
            {
                activator.Handle<string>(async str =>
                {
                    throw new ThisOneCannotBeSerialized("BAM!!!!!!!!!!!11111111111111111");
                });

                var network = new InMemNetwork();

                var bus = Configure.With(activator)
                    .Transport(t => t.UseInMemoryTransport(network, "unserializable exceptions"))
                    .Options(o => o.SimpleRetryStrategy(maxDeliveryAttempts: 1))
                    .Start();

                const string knownString = "JUST SOME LISP!!!!11((((((((((((((((((()))))))))))))))))))))))";

                await bus.SendLocal(knownString);

                var failedMessage = await network.WaitForNextMessageFrom("error");

                Assert.That(Encoding.UTF8.GetString(failedMessage.Body), Is.EqualTo(JsonConvert.SerializeObject(knownString)));
            }
        }
Esempio n. 2
0
        static IBus StartBus(InMemNetwork network, string queueName, ConcurrentQueue<string> recordedEvents)
        {
            var activator = new BuiltinHandlerActivator();

            activator.Handle(async (string message) =>
            {
                recordedEvents.Enqueue($"GOT MESSAGE: {message}");
            });

            return Configure.With(activator)
                .Transport(t => t.UseInMemoryTransport(network, queueName))
                .Options(o =>
                {
                    o.Decorate(c =>
                    {
                        var events = c.Get<BusLifetimeEvents>();

                        events.BusStarting += () => recordedEvents.Enqueue("Bus starting");
                        events.BusStarted += () => recordedEvents.Enqueue("Bus started");
                        events.BusDisposing += () => recordedEvents.Enqueue("Bus disposing");
                        events.BusDisposed += () => recordedEvents.Enqueue("Bus disposed");

                        return events;
                    });
                })
                .Start();
        }
        protected override void SetUp()
        {
            var inMemNetwork = new InMemNetwork();

            _service = CreateEndpoint(inMemNetwork, "service");
            _client = CreateEndpoint(inMemNetwork, "client");
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the transport, using the specified <see cref="InMemNetwork"/> to deliver/receive messages. This transport will have
        /// <paramref name="inputQueueAddress"/> as its input queue address, and thus will attempt to receive messages from the queue with that
        /// name out of the given <paramref name="network"/>
        /// </summary>
        public InMemTransport(InMemNetwork network, string inputQueueAddress)
        {
            if (network == null) throw new ArgumentNullException("network", "You need to provide a network that this in-mem transport should use for communication");

            _network = network;
            _inputQueueAddress = inputQueueAddress;
        }
        public async Task CanForwardToMultipleRecipients()
        {
            var network = new InMemNetwork();
            var activator = new BuiltinHandlerActivator();

            Using(activator);

            var recipients = new[] { "recipient-A", "recipient-B" }.ToList();

            recipients.ForEach(network.CreateQueue);

            Configure.With(activator)
                .Transport(t => t.UseInMemoryTransport(network, "forwarder"))
                .Routing(t =>
                {
                    t.AddTransportMessageForwarder(async transportMessage => ForwardAction.ForwardTo(recipients));
                })
                .Start();

            await activator.Bus.SendLocal("HEJ MED DIG!!!");

            var transportMessages = await Task.WhenAll(recipients.Select(async queue =>
            {
                var message = await network.WaitForNextMessageFrom(queue);

                return message;
            }));

            Assert.That(transportMessages.Length, Is.EqualTo(2));
        }
        protected override void SetUp()
        {
            var logger = new ListLoggerFactory(detailed: true);

            _network = new InMemNetwork();

            // start the external timeout manager
            Configure.With(Using(new BuiltinHandlerActivator()))
                .Logging(l => l.Use(logger))
                .Transport(t => t.UseInMemoryTransport(_network, _queueNameTimeoutManager))
                .Start();

            _gotTheMessage = new ManualResetEvent(false);

            // start the client
            var client = Using(new BuiltinHandlerActivator());

            client.Handle<string>(async str => _gotTheMessage.Set());

            Configure.With(client)
                .Logging(l => l.Use(logger))
                .Transport(t => t.UseInMemoryTransport(_network, _queueName))
                .Timeouts(t => t.UseExternalTimeoutManager(_queueNameTimeoutManager))
                .Start();

            _bus = client.Bus;
        }
Esempio n. 7
0
        protected override void SetUp()
        {
            var network = new InMemNetwork();

            _events = new ConcurrentQueue<string>();
            _uowActivator = new BuiltinHandlerActivator();
            _otherActivator = new BuiltinHandlerActivator();

            Using(_uowActivator);
            Using(_otherActivator);

            _uowBus = Configure.With(_uowActivator)
                .Logging(l => l.Console(LogLevel.Warn))
                .Transport(t => t.UseInMemoryTransport(network, UowQueueName))
                .Options(o =>
                {
                    o.EnableUnitOfWork(c => _events,
                        commitAction: (c, e) => RegisterEvent("uow committed"),
                        rollbackAction: (c, e) => RegisterEvent("uow rolled back"),
                        cleanupAction: (c, e) => RegisterEvent("uow cleaned up"));

                    o.SimpleRetryStrategy(maxDeliveryAttempts: 1);

                    //o.LogPipeline(true);
                })
                .Start();

            Configure.With(_otherActivator)
                .Logging(l => l.Console(LogLevel.Warn))
                .Transport(t => t.UseInMemoryTransport(network, OtherQueueName))
                .Start();
        }
Esempio n. 8
0
        protected override void SetUp()
        {
            _inMemNetwork = new InMemNetwork();
            _inMemDataStore = new InMemDataStore();

            _senderBus = StartBus("sender").Bus;
            _receiverActivator = StartBus("receiver");
        }
Esempio n. 9
0
        /// <summary>
        /// Creates the transport, using the specified <see cref="InMemNetwork"/> to deliver/receive messages. This transport will have
        /// <paramref name="inputQueueAddress"/> as its input queue address, and thus will attempt to receive messages from the queue with that
        /// name out of the given <paramref name="network"/>
        /// </summary>
        public InMemTransport(InMemNetwork network, string inputQueueAddress)
        {
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network), "You need to provide a network that this in-mem transport should use for communication");
            }

            _network           = network;
            _inputQueueAddress = inputQueueAddress;
        }
Esempio n. 10
0
        /// <summary>
        /// Creates the transport, using the specified <see cref="InMemNetwork"/> to deliver/receive messages. This transport will have
        /// <paramref name="inputQueueAddress"/> as its input queue address, and thus will attempt to receive messages from the queue with that
        /// name out of the given <paramref name="network"/>
        /// </summary>
        public InMemTransport(InMemNetwork network, string inputQueueAddress)
        {
            if (network == null) throw new ArgumentNullException("network");
            if (inputQueueAddress == null) throw new ArgumentNullException("inputQueueAddress");

            _network = network;
            _inputQueueAddress = inputQueueAddress;

            _network.CreateQueue(inputQueueAddress);
        }
Esempio n. 11
0
 protected override void SetUp()
 {
     _adapter = new BuiltinHandlerActivator();
     _network = new InMemNetwork();
     
     _bus = Configure.With(_adapter)
         .Transport(t => t.UseInMemoryTransport(_network, "test"))
         .Options(o => o.EnableMessageAuditing("audit"))
         .Start();
 }
Esempio n. 12
0
        protected override void SetUp()
        {
            _activator = Using(new BuiltinHandlerActivator());

            _network = new InMemNetwork();

            _bus = Configure.With(_activator)
                .Transport(t => t.UseInMemoryTransport(_network, InputQueueName))
                .Options(o => o.SimpleRetryStrategy(secondLevelRetriesEnabled: true))
                .Start();
        }
        BuiltinHandlerActivator CreateEndpoint(InMemNetwork inMemNetwork, string inputQueueName)
        {
            var service = Using(new BuiltinHandlerActivator());

            Configure.With(service)
                .Logging(l => l.Console(minLevel: LogLevel.Warn))
                .Transport(t => t.UseInMemoryTransport(inMemNetwork, inputQueueName))
                .Routing(r => r.TypeBased().Map<string>("service"))
                .Start();

            return service;
        }
Esempio n. 14
0
        protected override void SetUp()
        {
            _builtinHandlerActivator = new BuiltinHandlerActivator();
            
            Using(_builtinHandlerActivator);

            _network = new InMemNetwork();

            Configure.With(_builtinHandlerActivator)
                .Transport(t => t.UseInMemoryTransport(_network, InputQueueName))
                .Start();
        }
Esempio n. 15
0
        static TimeSpan RunTest(int numberOfMessages, PipelineStepProfilerStats profilerStats)
        {
            using (var adapter = new BuiltinHandlerActivator())
            {
                var network = new InMemNetwork();

                Configure.With(adapter)
                    .Logging(l => l.Console(LogLevel.Warn))
                    .Transport(t => t.UseInMemoryTransport(network, "perftest"))
                    .Options(o =>
                    {
                        o.SetNumberOfWorkers(0);
                        o.SetMaxParallelism(1);

                        o.Decorate<IPipeline>(c => new PipelineStepProfiler(c.Get<IPipeline>(), profilerStats));
                    })
                    .Start();

                var serializer = new JsonSerializer();
                var boy = new SomeMessage("hello there!");

                numberOfMessages.Times(() =>
                {
                    var headers = new Dictionary<string, string> { { Headers.MessageId, Guid.NewGuid().ToString() } };
                    var message = new Message(headers, boy);
                    var transportMessage = serializer.Serialize(message).Result;
                    var inMemTransportMessage = transportMessage.ToInMemTransportMessage();

                    network.Deliver("perftest", inMemTransportMessage);
                });


                var numberOfReceivedMessages = 0;
                var gotAllMessages = new ManualResetEvent(false);

                adapter.Handle<SomeMessage>(async m =>
                {
                    numberOfReceivedMessages++;
                    if (numberOfReceivedMessages == numberOfMessages)
                    {
                        gotAllMessages.Set();
                    }
                });

                var stopwatch = Stopwatch.StartNew();

                adapter.Bus.Advanced.Workers.SetNumberOfWorkers(1);
                gotAllMessages.WaitOrDie(TimeSpan.FromSeconds(30));

                return stopwatch.Elapsed;
            }
        }
Esempio n. 16
0
        BuiltinHandlerActivator GetEndpoint(InMemNetwork network, string queueName, Action<RebusConfigurer> additionalConfiguration = null)
        {
            var activator = Using(new BuiltinHandlerActivator());

            var configurer = Configure.With(activator)
                .Transport(t => t.UseInMemoryTransport(network, queueName));

            additionalConfiguration?.Invoke(configurer);

            configurer.Start();

            return activator;
        }
Esempio n. 17
0
        protected override void SetUp()
        {
            _listLoggerFactory = new ListLoggerFactory();
            _adapter = new BuiltinHandlerActivator();
            _network = new InMemNetwork(outputEventsToConsole: true);

            var bus = Configure.With(_adapter)
                .Logging(l => l.Use(_listLoggerFactory))
                .Transport(t => t.UseInMemoryTransport(_network, "test"))
                .Options(o => o.SimpleRetryStrategy("error", 3))
                .Start();

            Using(bus);
        }
        protected override void SetUp()
        {
            _network = new InMemNetwork();
            _subscriberStore = new InMemorySubscriberStore();

            _activator = new BuiltinHandlerActivator();

            Using(_activator);

            Configure.With(_activator)
                .Transport(t => t.UseInMemoryTransport(_network, "endpoint1"))
                .Subscriptions(s => s.StoreInMemory(_subscriberStore))
                .Start();
        }
Esempio n. 19
0
        protected override void SetUp()
        {
            _activator = Using(new BuiltinHandlerActivator());
            _network = new InMemNetwork();

            Configure.With(_activator)
                .Transport(t => t.UseInMemoryTransport(_network, "disable-encryption"))
                .Options(o =>
                {
                    o.EnableEncryption("u4cB8CJyfCFpffuYREmO6qGA8xRdaO2lAt95sp2JEFU=");
                })
                .Start();

            _bus = _activator.Bus;
        }
Esempio n. 20
0
        /// <summary>
        /// Creates the transport, using the specified <see cref="InMemNetwork"/> to deliver/receive messages. This transport will have
        /// <paramref name="inputQueueAddress"/> as its input queue address, and thus will attempt to receive messages from the queue with that
        /// name out of the given <paramref name="network"/>
        /// </summary>
        public InMemTransport(InMemNetwork network, string inputQueueAddress)
        {
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }
            if (inputQueueAddress == null)
            {
                throw new ArgumentNullException("inputQueueAddress");
            }

            _network           = network;
            _inputQueueAddress = inputQueueAddress;

            _network.CreateQueue(inputQueueAddress);
        }
        protected override void SetUp()
        {
            _network = new InMemNetwork();

            _forwarderActivator = Using(new BuiltinHandlerActivator());
            
            Configure.With(_forwarderActivator)
                .Transport(t => t.UseInMemoryTransport(_network, "message forwarder"))
                .Start();

            _receiverActivator = Using(new BuiltinHandlerActivator());
            
            Configure.With(_receiverActivator)
                .Transport(t => t.UseInMemoryTransport(_network, ForwardedMessagesQueue))
                .Start();
        }
Esempio n. 22
0
        protected override void SetUp()
        {
            var network = new InMemNetwork();
            var subscriberStore = new InMemorySubscriberStore();
            _publisher = GetEndpoint(network, "publisher", c =>
            {
                c.Subscriptions(s => s.StoreInMemory(subscriberStore));
                c.Routing(r => r.TypeBased());
            });

            _client1GotTheEvent = new ManualResetEvent(false);
            _client1 = GetEndpoint(network, "client1", c =>
            {
                c.Routing(r => r.TypeBased().Map<SomeKindOfEvent>("publisher"));
            });
            _client1.Handle<SomeKindOfEvent>(async e => _client1GotTheEvent.Set());
        }
Esempio n. 23
0
        protected override void SetUp()
        {
            SqlTestHelper.DropTable("subscriptions");

            var network = new InMemNetwork();
            _publisher = GetEndpoint(network, "publisher", c =>
            {
                c.Subscriptions(s => s.StoreInSqlServer(SqlTestHelper.ConnectionString, "subscriptions"));
                c.Routing(r => r.TypeBased());
            });

            _client1GotTheEvent = new ManualResetEvent(false);
            _client1 = GetEndpoint(network, "client1", c =>
            {
                c.Routing(r => r.TypeBased().Map<SomeKindOfEvent>("publisher"));
            });
            _client1.Handle<SomeKindOfEvent>(async e => _client1GotTheEvent.Set());
        }
        protected override void SetUp()
        {
            _network = new InMemNetwork();

            Configure.With(Using(new BuiltinHandlerActivator()))
                .Transport(t => t.UseInMemoryTransport(_network, TimeoutsQueueName))
                .Start();

            _destination = new BuiltinHandlerActivator();
            Configure.With(Using(_destination))
                .Transport(t => t.UseInMemoryTransport(_network, DestinationQueueName))
                .Start();

            _oneWayClient = Configure.With(Using(new BuiltinHandlerActivator()))
                .Transport(t => t.UseInMemoryTransportAsOneWayClient(_network))
                .Timeouts(t => t.UseExternalTimeoutManager(TimeoutsQueueName))
                .Start();
        }
Esempio n. 25
0
        public void RecordsTheEventsAsExpected()
        {
            const string body = "hej med dig!!";
            const string queueName = "lifetime-events";

            var recordedEvents = new ConcurrentQueue<string>();
            var network = new InMemNetwork();

            using (var bus = StartBus(network, queueName, recordedEvents))
            {
                Thread.Sleep(500);

                bus.SendLocal(body).Wait();

                Thread.Sleep(500);
            }

            Console.WriteLine(string.Join(Environment.NewLine, recordedEvents));
        }
        protected override void SetUp()
        {
            var network = new InMemNetwork();

            _events = new ConcurrentQueue<string>();
            _uowActivator = new BuiltinHandlerActivator();

            Using(_uowActivator);

            _loggerFactory = new ListLoggerFactory(outputToConsole:true);

            Configure.With(_uowActivator)
                .Logging(l => l.Use(_loggerFactory))
                .Transport(t => t.UseInMemoryTransport(network, UowQueueName))
                .Options(o =>
                {
                    o.EnableUnitOfWork(async c => _events, commitAction: async (c, e) => {});
                    o.SimpleRetryStrategy(maxDeliveryAttempts: 1);
                })
                .Start();
        }
Esempio n. 27
0
        protected override void SetUp()
        {
            var network = new InMemNetwork(true);

            _subscriberHandlers = new BuiltinHandlerActivator();

            _subscriberBus = Configure.With(_subscriberHandlers)
                .Transport(t => t.UseInMemoryTransport(network, SubscriberInputQueue))
                //.Transport(t => t.UseMsmq(SubscriberInputQueue))
                .Routing(r => r.TopicBased().Map("someTopic", PublisherInputQueue))
                .Start();

            Using(_subscriberBus);

            _publisherBus = Configure.With(new BuiltinHandlerActivator())
                .Transport(t => t.UseInMemoryTransport(network, PublisherInputQueue))
                //.Transport(t => t.UseMsmq(PublisherInputQueue))
                .Routing(r => r.TopicBased().Map("someTopic", PublisherInputQueue))
                .Start();

            Using(_publisherBus);
        }
        /// <summary>
        /// Configures Rebus to use in-mem message queues, delivering/receiving from the specified <see cref="InMemNetwork"/>
        /// </summary>
        public static void UseInMemoryTransport(this StandardConfigurer <ITransport> configurer, InMemNetwork network, string inputQueueName)
        {
            if (configurer == null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network));
            }
            if (inputQueueName == null)
            {
                throw new ArgumentNullException(nameof(inputQueueName));
            }

            configurer.OtherService <InMemTransport>()
            .Register(context => new InMemTransport(network, inputQueueName));

            configurer.OtherService <ITransportInspector>()
            .Register(context => context.Get <InMemTransport>());

            configurer.Register(context => context.Get <InMemTransport>());
        }
Esempio n. 29
0
 /// <summary>
 /// Configures Rebus to use in-mem message queues, delivering/receiving from the specified <see cref="InMemNetwork"/>
 /// </summary>
 public static void UseInMemoryTransport(this StandardConfigurer <ITransport> configurer, InMemNetwork network, string inputQueueName)
 {
     configurer.Register(context => new InMemTransport(network, inputQueueName));
 }
Esempio n. 30
0
 protected override void SetUp()
 {
     _network = new InMemNetwork(true);
 }
        /// <summary>
        /// Configures Rebus to use in-mem message queues, configuring this instance to be a one-way client
        /// </summary>
        public static void UseInMemoryTransportAsOneWayClient(this StandardConfigurer<ITransport> configurer, InMemNetwork network)
        {
            configurer.Register(c => new InMemTransport(network, null));

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);
        }
 /// <summary>
 /// Configures Rebus to use in-mem message queues, delivering/receiving from the specified <see cref="InMemNetwork"/>
 /// </summary>
 public static void UseInMemoryTransport(this StandardConfigurer<ITransport> configurer, InMemNetwork network, string inputQueueName)
 {
     configurer.Register(context => new InMemTransport(network, inputQueueName));
 }
        /// <summary>
        /// Configures Rebus to use in-mem message queues, configuring this instance to be a one-way client
        /// </summary>
        public static void UseInMemoryTransportAsOneWayClient(this StandardConfigurer <ITransport> configurer, InMemNetwork network)
        {
            configurer.Register(c => new InMemTransport(network, null));

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);
        }
        /// <summary>
        /// Configures Rebus to use in-mem message queues, configuring this instance to be a one-way client
        /// </summary>
        public static void UseInMemoryTransportAsOneWayClient(this StandardConfigurer <ITransport> configurer, InMemNetwork network)
        {
            if (configurer == null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }
            if (network == null)
            {
                throw new ArgumentNullException(nameof(network));
            }

            configurer.Register(c => new InMemTransport(network, null));

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);
        }
Esempio n. 35
0
 protected override void SetUp()
 {
     _doneWork = new ConcurrentQueue<DoneWork>();
     _network = new InMemNetwork();
 }