public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var queue = new Queue("test_queue", false);

            var are = new AutoResetEvent(false);
            mockBuilder.Bus.Advanced.Consume<ITestMessageInterface>(queue, (message, info) => Task.Factory.StartNew(() =>
                {
                    receivedMessage = message.Body;
                    are.Set();
                }));

            var publishedMessage = new Implementation { Text = "Hello Polymorphs!" };
            var body = new JsonSerializer(new TypeNameSerializer()).MessageToBytes(publishedMessage);
            var properties = new BasicProperties
                {
                    Type = new TypeNameSerializer().Serialize(typeof(Implementation))
                };

            mockBuilder.Consumers[0].HandleBasicDeliver(
                "consumer_tag",
                0,
                false,
                "exchange",
                "routing_key",
                properties,
                body
                );

            are.WaitOne(1000);
        }
Пример #2
0
        public When_a_queue_is_deleted()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var queue = new Queue("my_queue", false);

            advancedBus.QueueDelete(queue);
        }
Пример #3
0
        public void ConsumeFromAQueue()
        {
            var queue = new Queue("my_queue", false);
            advancedBus.Consume(queue, (body, properties, info) => Task.Factory.StartNew(() =>
                {
                    var message = Encoding.UTF8.GetString(body);
                    Console.Out.WriteLine("Got message: '{0}'", message);
                }));

            Thread.Sleep(500);
        }
Пример #4
0
        public When_a_queue_is_unbound_from_an_exchange()
        {
            mockBuilder = new MockBuilder();
            advancedBus = mockBuilder.Bus.Advanced;

            var exchange = new Exchange("my_exchange");
            var queue    = new Queue("my_queue", false);

            binding = advancedBus.Bind(exchange, queue, "my_routing_key");
            advancedBus.Unbind(binding);
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var queue = new Queue("my_queue", false);

            var cancelSubscription = mockBuilder.Bus.Advanced
                .Consume(queue, (bytes, properties, arg3) => Task.Factory.StartNew(() => { }));

            cancelSubscription.Dispose();
        }
        public void Should_wrap_error_messages_correctly()
        {
            var typeNameSerializer = bus.Advanced.Container.Resolve<ITypeNameSerializer>();
            var serializer = bus.Advanced.Container.Resolve<ISerializer>();
            var conventions = bus.Advanced.Container.Resolve<IConventions>();

            var errorQueue = new Queue(conventions.ErrorQueueNamingConvention(), false);
            bus.Advanced.QueuePurge(errorQueue);

            var typeName = typeNameSerializer.Serialize(typeof(MyErrorTestMessage));
            var exchange = this.bus.Advanced.ExchangeDeclare(typeName, ExchangeType.Topic);

            bus.Subscribe<MyErrorTestMessage>("exceptionTest", _ =>
            {
                throw new Exception("Hello Error Handler!");
            });

            // give the subscription a chance to complete
            Thread.Sleep(500);

            var message = new MyErrorTestMessage { Id = 444, Name = "I cause an error. Naughty me!" };
            var headers = new Dictionary<string, object>()
                          {
                              { "AString", "ThisIsAString" },
                              { "AnInt", 123 }
                          };
            var correlationId = Guid.NewGuid().ToString();

            var props = new MessageProperties()
            {
                Type = typeName,
                Headers = headers,
                CorrelationId = correlationId
            };

             bus.Advanced.Publish(exchange, typeNameSerializer.Serialize(typeof(MyErrorTestMessage)), true, props, serializer.MessageToBytes(message));

            // give the publish a chance to get to rabbit and back
            // also allow the DefaultConsumerErrorStrategy time to spin up its connection
            Thread.Sleep(1000);

            var errorMessage = this.bus.Advanced.Get<Error>(errorQueue);
            errorMessage.MessageAvailable.ShouldBeTrue();

            var error = errorMessage.Message.Body;
            Console.WriteLine(error.ToString());

            error.BasicProperties.Type.ShouldEqual(typeNameSerializer.Serialize(typeof(MyErrorTestMessage)));
            error.BasicProperties.CorrelationId.ShouldEqual(correlationId);
            error.BasicProperties.Headers.ShouldEqual(headers);
            error.BasicProperties.Headers["AString"].ShouldEqual("ThisIsAString");
            error.BasicProperties.Headers["AnInt"].ShouldEqual(123);
        }
Пример #7
0
        protected void StartConsumer(Action<byte[], MessageProperties, MessageReceivedInfo> handler)
        {
            ConsumerWasInvoked = false;
            var queue = new Queue("my_queue", false);
            MockBuilder.Bus.Advanced.Consume(queue, (body, properties, messageInfo) => Task.Factory.StartNew(() =>
                {
                    DeliveredMessageBody = body;
                    DeliveredMessageProperties = properties;
                    DeliveredMessageInfo = messageInfo;

                    handler(body, properties, messageInfo);
                    ConsumerWasInvoked = true;
                }, Cancellation.Token));
        }
        public void SetUp()
        {
            mockBuilder = new MockBuilder();

            var queue = new Queue("my_queue", false);

            mockBuilder.Bus.Advanced.Consume(queue, (bytes, properties, arg3) => Task.Factory.StartNew(() => { }));

            var are = new AutoResetEvent(false);
            mockBuilder.EventBus.Subscribe<ConsumerModelDisposedEvent>(x => are.Set());

            mockBuilder.Consumers[0].HandleBasicCancel("consumer_tag");

            are.WaitOne(500);
        }