示例#1
0
    void SetUpBus(Action <OptionsConfigurer> configurer)
    {
        _network.CreateQueue(DestinationQueueName);

        var handlerActivator = Using(new BuiltinHandlerActivator());

        var bus = Configure.With(handlerActivator)
                  .Logging(l => l.Console(LogLevel.Warn))
                  .Transport(t => t.UseInMemoryTransport(_network, InputQueueName))
                  .Routing(r => r.TypeBased().Map <string>(DestinationQueueName))
                  .Options(configurer)
                  .Start();

        bus.Send("hej med dig min ven!").Wait();
    }
示例#2
0
        protected override void SetUp()
        {
            _network = new InMemNetwork();

            _network.CreateQueue(DestinationAddress);
            _activator = new BuiltinHandlerActivator();

            Using(_activator);

            _starter = Configure.With(_activator)
                       .Transport(t => t.UseInMemoryTransport(_network, "test-queue"))
                       .Routing(r => r.TypeBased().Map <string>(DestinationAddress))
                       .Timeouts(t => t.StoreInMemory())
                       .Create();
        }
示例#3
0
        public void ItWorks_Complete()
        {
            const string queueName = "destination-queue";

            var network = new InMemNetwork();

            network.CreateQueue(queueName);

            RunTest(network, destinationAddress: queueName, complete: true);

            var transportMessage = network.GetNextOrNull(queueName)?.ToTransportMessage();

            Assert.That(transportMessage, Is.Not.Null);
            Assert.That(Encoding.UTF8.GetString(transportMessage.Body), Is.EqualTo(@"""HEJ MED DIG"""));
        }
        public async Task CanRetryForever()
        {
            const string recipientQueueName = "recipient";
            var          network            = new InMemNetwork();
            var          activator          = new BuiltinHandlerActivator();

            Using(activator);

            network.CreateQueue(recipientQueueName);

            var bus = GetFailingBus(activator, network, recipientQueueName, ErrorBehavior.RetryForever);

            await bus.SendLocal("HEJ MED DIG!!!");

            var message = await network.WaitForNextMessageFrom(recipientQueueName);

            Assert.That(Encoding.UTF8.GetString(message.Body), Is.EqualTo(@"""HEJ MED DIG!!!"""));
        }
        public async Task ContinuationsCanStillUseTheBus()
        {
            const string queueName = "another-queue";

            _network.CreateQueue(queueName);

            _activator.Bus.Advanced.Workers.SetNumberOfWorkers(1);

            var gotMessage          = new ManualResetEvent(false);
            var doneHandlingMessage = new ManualResetEvent(false);

            _activator.Handle <string>(async(bus, message) =>
            {
                gotMessage.Set();

                Printt("Got message - waiting 3 s...");

                await Task.Delay(3000);

                Printt("Done waiting :)");

                await bus.Advanced.Routing.Send(queueName, "JAJA DET VIRKER!");

                doneHandlingMessage.Set();
            });

            // send message
            await _activator.Bus.SendLocal("hej med dig");

            // wait for message to be received and then immediately shutdown the bus
            gotMessage.WaitOrDie(TimeSpan.FromSeconds(3), "Did not receive message within timeout");

            CleanUpDisposables();

            // wait for message to have been handled to end
            doneHandlingMessage.WaitOrDie(TimeSpan.FromSeconds(6), "Did not finish handling the message within expected timeframe");

            // wait for message to pop up in the expected queue
            var transportMessage = await _network.WaitForNextMessageFrom(queueName);

            Assert.That(Encoding.UTF8.GetString(transportMessage.Body), Is.EqualTo(@"""JAJA DET VIRKER!"""));
        }
        public async Task CanFailFastAndForwardToErrorQueue()
        {
            const string recipientQueueName = "recipient";
            var          network            = new InMemNetwork();
            var          activator          = new BuiltinHandlerActivator();

            Using(activator);

            network.CreateQueue(recipientQueueName);

            var bus = GetFailingBus(activator, network, recipientQueueName, ErrorBehavior.ForwardToErrorQueue);

            await bus.SendLocal("HEJ MED DIG!!!");

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

            Assert.That(Encoding.UTF8.GetString(message.Body), Is.EqualTo(@"""HEJ MED DIG!!!"""));
            Assert.That(message.Headers.GetValueOrNull(Headers.SourceQueue), Is.EqualTo("forwarder"));
            Assert.That(message.Headers.GetValueOrNull(Headers.ErrorDetails), Does.Contain("fake an error"));
        }
        public void CheckThatItDoesNotEnlistInOtherBusTransactionCotnext()
        {
            _listLoggerFactory = new ListLoggerFactory(true);

            _firstNetwork  = new InMemNetwork();
            _secondNetwork = new InMemNetwork();

            _activator1 = StartBus(_firstNetwork, "endpoint");
            _activator2 = StartBus(_secondNetwork, "proper-destination");

            // prepare dead-end queue on first network
            _firstNetwork.CreateQueue("dead-end");

            // register handler on first network's endpoint that forwards to 'proper-destination' by using the other bus
            _activator1.Register(() =>
            {
                var otherBus = _activator2.Bus;
                var handler  = new HandlerThatUsesAnotherBus(otherBus);
                return(handler);
            });

            // prepare handler on the bus on the other network so we can receive the message
            var gotTheMessage = new ManualResetEvent(false);

            _activator2.Handle <string>(async str => gotTheMessage.Set());


            _activator1.Bus.Advanced.Workers.SetNumberOfWorkers(1);
            _activator2.Bus.Advanced.Workers.SetNumberOfWorkers(1);


            _activator1.Bus.SendLocal("hej med dig min ven!!").Wait();

            gotTheMessage.WaitOrDie(TimeSpan.FromSeconds(3), @"Looks like we never got the message.

If everything was working properly, the forwarded message would have
been sent in its own transaction context, thus sent&committed
immediately when calling bus.....Forward");
        }
        public void OnlyReceivesPublishedEventWhenRebusTransactionScopeIsCompleted()
        {
            var network         = new InMemNetwork();
            var subscriberStore = new InMemorySubscriberStore();

            network.CreateQueue("subscriber");
            subscriberStore.AddSubscriber(typeof(TestEvent).GetSimpleAssemblyQualifiedName(), "subscriber");

            var bus = Configure.With(new BuiltinHandlerActivator())
                      .Subscriptions(config => config.StoreInMemory(subscriberStore))
                      .Transport(configurer => configurer.UseInMemoryTransport(network, "Test"))
                      .Start();

            using (var scope = new RebusTransactionScope())
            {
                bus.Advanced.SyncBus.Publish(new TestEvent("completed"));
                scope.Complete();
            }

            using (new RebusTransactionScope())
            {
                bus.Advanced.SyncBus.Publish(new TestEvent("not completed"));
                // this scope is intentionally not completed!
            }

            var messages = network.GetMessages("subscriber").ToList();

            Assert.That(messages.Count, Is.EqualTo(1));

            var transportMessage = messages.First();

            Assert.That(transportMessage.Headers.GetValue(Headers.Type), Is.EqualTo(typeof(TestEvent).GetSimpleAssemblyQualifiedName()));

            var json      = Encoding.UTF8.GetString(transportMessage.Body);
            var testEvent = JsonConvert.DeserializeObject <TestEvent>(json);

            Assert.That(testEvent.Label, Is.EqualTo("completed"));
        }
 public void CreateQueue(string address)
 {
     _network.CreateQueue(address);
 }
示例#10
0
 public void Queues_ReturnsCreatedQueues()
 {
     _inMemNetwork.CreateQueue("test");
     Assert.That(_inMemNetwork.Queues, Is.EquivalentTo(new[] { "input", "test" }));
 }
示例#11
0
 public void SetUp()
 {
     _inMemNetwork = new InMemNetwork();
     _inMemNetwork.CreateQueue("input");
 }