Exemple #1
0
        private static void Main()
        {
            const String routingKey = "routing_key";
            const String endpointUrl = "amqp://*****:*****@localhost:5672/";
            IMessageTypeResolver resolver = new MessageBindingResolver(typeof(Foo).Assembly);

            var broker = Broker.New(_ =>
            {
                _.Endpoint(new Uri(endpointUrl, UriKind.Absolute));
                _.ResolveMessageTypeBy(resolver);
            });

            var exchange = broker.DeclareDirectExchange("source_exchange");
            var queue = broker.DeclareQueue("my_test_queue");
            broker.DeclareExchangeBinding(exchange, queue, routingKey);
            broker.SubscribeByAtLeastOnce(queue, _ => _.Consumes(new FooConsumer1()));
            broker.SubscribeByAtLeastOnce(queue, _ => _.Consumes(new FooConsumer2()));
            var connection = broker.Connect();

            for (var i = 0; i < 5; i++)
            {
                var message = new OutboundMessage<Foo>(new Foo { Bar = i });
                connection.PublishAsync(message, exchange, routingKey);
            }

            Console.ReadLine();
            connection.Dispose();
        }
Exemple #2
0
 public void FallbackResolveType()
 {
     var type = typeof(Bar);
     var resolver = new MessageBindingResolver(type.Assembly);
     var binding = resolver.Resolve<Bar>();
     Assert.Equal("urn:message:Carrot.Tests.Bar", binding.RawName);
 }
Exemple #3
0
 public void ResolveType()
 {
     var type = typeof(Foo);
     var resolver = new MessageBindingResolver(type.Assembly);
     var messageType = resolver.Resolve<Foo>();
     Assert.Equal("urn:message:foo", messageType.RawName);
 }
Exemple #4
0
 public void CannotResolve()
 {
     const String source = "urn:message:no-resolve";
     var type = typeof(Foo);
     var resolver = new MessageBindingResolver(type.Assembly);
     Assert.IsType<EmptyMessageType>(resolver.Resolve(source));
 }
Exemple #5
0
        private static void Main()
        {
            const String         routingKey  = "routing_key";
            const String         endpointUrl = "amqp://*****:*****@localhost:5672/";
            IMessageTypeResolver resolver    = new MessageBindingResolver(typeof(Foo).Assembly);

            var broker = Broker.New(_ =>
            {
                _.Endpoint(new Uri(endpointUrl, UriKind.Absolute));
                _.ResolveMessageTypeBy(resolver);
            });

            var exchange = broker.DeclareDirectExchange("source_exchange");
            var queue    = broker.DeclareQueue("my_test_queue");

            broker.DeclareExchangeBinding(exchange, queue, routingKey);
            broker.SubscribeByAtLeastOnce(queue, _ => _.Consumes(new FooConsumer1()));
            broker.SubscribeByAtLeastOnce(queue, _ => _.Consumes(new FooConsumer2()));
            var connection = broker.Connect();

            for (var i = 0; i < 5; i++)
            {
                var message = new OutboundMessage <Foo>(new Foo {
                    Bar = i
                });
                connection.PublishAsync(message, exchange, routingKey);
            }

            Console.ReadLine();
            connection.Dispose();
        }
Exemple #6
0
 public void SettingExpiration()
 {
     var type = typeof(Buzz);
     var resolver = new MessageBindingResolver(type.Assembly);
     var binding = resolver.Resolve<Buzz>();
     Assert.Equal("urn:message:buzz", binding.RawName);
     Assert.Equal(TimeSpan.FromSeconds(19), binding.ExpiresAfter);
 }
Exemple #7
0
 public void ResolveType()
 {
     var type = typeof(Foo);
     var resolver = new MessageBindingResolver(type.Assembly);
     var binding = resolver.Resolve<Foo>();
     Assert.Equal("urn:message:foo", binding.RawName);
     Assert.False(binding.ExpiresAfter.HasValue);
 }
        public void FallbackResolveType()
        {
            var type     = typeof(Bar);
            var resolver = new MessageBindingResolver(type.Assembly);
            var binding  = resolver.Resolve <Bar>();

            Assert.Equal("urn:message:Carrot.Tests.Bar", binding.RawName);
        }
Exemple #9
0
 public void CannotResolve()
 {
     const String source = "urn:message:no-resolve";
     var args = new BasicDeliverEventArgs { BasicProperties = new BasicProperties { Type = source } };
     var context = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
     var type = typeof(Foo);
     var resolver = new MessageBindingResolver(type.Assembly);
     Assert.IsType<EmptyMessageBinding>(resolver.Resolve(context));
 }
Exemple #10
0
        public void SettingExpiration()
        {
            var type     = typeof(Buzz);
            var resolver = new MessageBindingResolver(type.Assembly);
            var binding  = resolver.Resolve <Buzz>();

            Assert.Equal("urn:message:buzz", binding.RawName);
            Assert.Equal(TimeSpan.FromSeconds(19), binding.ExpiresAfter);
        }
Exemple #11
0
        public void ResolveType()
        {
            var type     = typeof(Foo);
            var resolver = new MessageBindingResolver(type.Assembly);
            var binding  = resolver.Resolve <Foo>();

            Assert.Equal("urn:message:foo", binding.RawName);
            Assert.False(binding.ExpiresAfter.HasValue);
        }
Exemple #12
0
 public void Resolve()
 {
     const String source = "urn:message:foo";
     var type = typeof(Foo);
     var resolver = new MessageBindingResolver(type.Assembly);
     var messageType = resolver.Resolve(source);
     Assert.Equal(source, messageType.RawName);
     Assert.Equal(type, messageType.RuntimeType);
 }
Exemple #13
0
 public void Resolve()
 {
     const String source = "urn:message:foo";
     var args = new BasicDeliverEventArgs { BasicProperties = new BasicProperties { Type = source } };
     var context = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
     var type = typeof(Foo);
     var resolver = new MessageBindingResolver(type.Assembly);
     var binding = resolver.Resolve(context);
     Assert.Equal(source, binding.RawName);
     Assert.Equal(type, binding.RuntimeType);
 }
Exemple #14
0
        public void CannotResolve()
        {
            const String source = "urn:message:no-resolve";
            var          args   = new BasicDeliverEventArgs {
                BasicProperties = new BasicProperties {
                    Type = source
                }
            };
            var context  = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
            var type     = typeof(Foo);
            var resolver = new MessageBindingResolver(type.Assembly);

            Assert.IsType <EmptyMessageBinding>(resolver.Resolve(context));
        }
Exemple #15
0
        public void Resolve()
        {
            const String source = "urn:message:foo";
            var          args   = new BasicDeliverEventArgs {
                BasicProperties = new BasicProperties {
                    Type = source
                }
            };
            var context  = ConsumedMessageContext.FromBasicDeliverEventArgs(args);
            var type     = typeof(Foo);
            var resolver = new MessageBindingResolver(type.Assembly);
            var binding  = resolver.Resolve(context);

            Assert.Equal(source, binding.RawName);
            Assert.Equal(type, binding.RuntimeType);
        }
Exemple #16
0
        private static void Main(String[] args)
        {
            const String routingKey        = "request_routing_key";
            const String endpointUrl       = "amqp://*****:*****@localhost:5672/";
            const String replyQueueName    = "reply_to_queue";
            const String replyExchangeName = "reply_exchange";

            IMessageTypeResolver resolver = new MessageBindingResolver(typeof(Response).Assembly);

            var broker = Broker.New(_ =>
            {
                _.Endpoint(new Uri(endpointUrl, UriKind.Absolute));
                _.ResolveMessageTypeBy(resolver);
            });

            var exchange = broker.DeclareDirectExchange("request_exchange");
            var queue    = broker.DeclareQueue("request_queue");

            broker.DeclareExchangeBinding(exchange, queue, routingKey);
            broker.SubscribeByAtLeastOnce(queue, _ => _.Consumes(new RequestConsumer(endpointUrl)));

            var replyExchange = broker.DeclareDirectExchange(replyExchangeName);
            var replyQueue    = broker.DeclareQueue(replyQueueName);

            broker.DeclareExchangeBinding(replyExchange, replyQueue, replyQueueName);
            broker.SubscribeByAtLeastOnce(replyQueue, _ => _.Consumes(new ResponseConsumer()));

            var connection = broker.Connect();

            var message = new OutboundMessage <Request>(new Request {
                Bar = 42
            });

            message.SetCorrelationId(Guid.NewGuid().ToString());
            message.SetReply(new DirectReplyConfiguration(replyExchangeName, replyQueueName));
            connection.PublishAsync(message, exchange, routingKey);

            Console.ReadLine();
            connection.Dispose();
        }