コード例 #1
0
        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)));
            }
        }
コード例 #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();
        }
コード例 #3
0
        protected override void SetUp()
        {
            var inMemNetwork = new InMemNetwork();

            _service = CreateEndpoint(inMemNetwork, "service");
            _client = CreateEndpoint(inMemNetwork, "client");
        }
コード例 #4
0
ファイル: InMemTransport.cs プロジェクト: netojoaop/Rebus
        /// <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;
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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;
        }
コード例 #7
0
ファイル: TestUnitOfWork.cs プロジェクト: RichieYang/Rebus
        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();
        }
コード例 #8
0
ファイル: SimpleTest.cs プロジェクト: RichieYang/Rebus
        protected override void SetUp()
        {
            _inMemNetwork = new InMemNetwork();
            _inMemDataStore = new InMemDataStore();

            _senderBus = StartBus("sender").Bus;
            _receiverActivator = StartBus("receiver");
        }
コード例 #9
0
ファイル: InMemTransport.cs プロジェクト: zszqwe/Rebus
        /// <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;
        }
コード例 #10
0
ファイル: InMemTransport.cs プロジェクト: geffzhang/Rebus
        /// <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);
        }
コード例 #11
0
ファイル: TestMessageAuditing.cs プロジェクト: mhertis/Rebus
 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();
 }
コード例 #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();
        }
コード例 #13
0
        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;
        }
コード例 #14
0
ファイル: TestDynamicJil.cs プロジェクト: xenoputtss/Rebus
        protected override void SetUp()
        {
            _builtinHandlerActivator = new BuiltinHandlerActivator();
            
            Using(_builtinHandlerActivator);

            _network = new InMemNetwork();

            Configure.With(_builtinHandlerActivator)
                .Transport(t => t.UseInMemoryTransport(_network, InputQueueName))
                .Start();
        }
コード例 #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;
            }
        }
コード例 #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;
        }
コード例 #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);
        }
コード例 #18
0
        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();
        }
コード例 #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;
        }
コード例 #20
0
ファイル: InMemTransport.cs プロジェクト: mhertis/Rebus
        /// <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);
        }
コード例 #21
0
        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();
        }
コード例 #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());
        }
コード例 #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());
        }
コード例 #24
0
        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();
        }
コード例 #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();
        }
コード例 #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);
        }
コード例 #28
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)
        {
            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>());
        }
コード例 #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));
 }
コード例 #30
0
ファイル: TestInMemNetwork.cs プロジェクト: RichieYang/Rebus
 protected override void SetUp()
 {
     _network = new InMemNetwork(true);
 }
コード例 #31
0
        /// <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);
        }
コード例 #32
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));
 }
コード例 #33
0
        /// <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);
        }
コード例 #34
0
        /// <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);
        }
コード例 #35
0
ファイル: TestHeaderBasedRouting.cs プロジェクト: nls75/Rebus
 protected override void SetUp()
 {
     _doneWork = new ConcurrentQueue<DoneWork>();
     _network = new InMemNetwork();
 }