Описание очереди RabbitMq.
상속: ITopologyEntity, IListeningSource
예제 #1
0
            public void should_return_response()
            {
                int result = 0;

                IBus producer = this.StartBus(
                    "producer",
                    cfg => cfg.Route("dummy.request")
                    .WithCallbackEndpoint(
                        b =>
                {
                    Exchange e = b.Topology.Declare(Exchange.Named("dummy.response").AutoDelete);
                    Queue q    = b.Topology.Declare(Queue.Named("dummy.response").AutoDelete.Exclusive);

                    b.Topology.Bind(e, q);

                    return(new SubscriptionEndpoint(q, e));
                }));

                this.StartBus(
                    "consumer",
                    cfg => cfg.On <DummyRequest>("dummy.request")
                    .ReactWith((m, ctx) => ctx.Reply(new DummyResponse(m.Num * 2))));

                Task <int> response = producer
                                      .RequestAsync <DummyRequest, DummyResponse>("dummy.request", new DummyRequest(13))
                                      .ContinueWith(t => result = t.Result.Num);

                response.Wait(1.Minutes()).Should().BeTrue();
                result.Should().Be(26);
            }
예제 #2
0
            public void CanConsumeWithWrongLabel()
            {
                var    autoReset    = new AutoResetEvent(false);
                string messageLabel = "command.handle.this";
                var    producer     = this.StartBus(
                    "producer",
                    cfg => cfg.Route(messageLabel));

                var consumer = this.StartBus(
                    "consumer",
                    cfg =>
                    cfg
                    .On <object>(messageLabel + ".new")
                    .ReactWith(
                        m =>
                {
                    autoReset.Set();
                })
                    .WithEndpoint(
                        builder =>
                {
                    Exchange e = builder.Topology.Declare(Exchange.Named(messageLabel).Fanout.Durable);
                    Queue q    = builder.Topology.Declare(Queue.Named(messageLabel + ".new"));

                    builder.Topology.Bind(e, q);

                    return(new SubscriptionEndpoint(q, new StaticRouteResolver(e)));
                }));

                producer.Emit(messageLabel, new object());
                Assert.IsTrue(autoReset.WaitOne(TimeSpan.FromSeconds(1)), "Сообщение должно быть получено.");
                consumer.WhenReady.WaitOne();
            }
예제 #3
0
 /// <summary>
 /// The bind.
 /// </summary>
 /// <param name="topology">
 /// The topology.
 /// </param>
 /// <param name="exchangeName">
 /// The exchange name.
 /// </param>
 /// <param name="queue">
 /// The queue.
 /// </param>
 /// <param name="routingKey">
 /// The routing key.
 /// </param>
 public static void Bind(this ITopologyBuilder topology, string exchangeName, Queue queue, string routingKey = "")
 {
     Bind(
         topology,
         Exchange.Named(exchangeName).
             Instance,
         queue,
         routingKey);
 }
예제 #4
0
            public void should_move_messages_to_separate_queue()
            {
                IBus producer = this.StartBus("producer", cfg => cfg.Route("boo"));

                this.StartBus(
                    "consumer",
                    cfg =>
                {
                    cfg.Route("all.broken")
                    .ConfiguredWith(
                        b =>
                    {
                        Exchange e = b.Topology.Declare(Exchange.Named("all.broken"));
                        Queue q    = b.Topology.Declare(Queue.Named("all.broken"));
                        b.Topology.Bind(e, q);
                        return(e);
                    });
                    cfg.OnFailed(
                        d =>
                    {
                        d.Forward("all.broken", d.BuildFaultMessage());
                        d.Accept();
                    });

                    cfg.On <BooMessage>("boo")
                    .ReactWith((m, ctx) => { throw new IOException(); })
                    .RequiresAccept();
                });

                producer.Emit("boo", new FooMessage(13));
                producer.Emit("boo", new FooMessage(13));
                producer.Emit("boo", new FooMessage(13));

                Thread.Sleep(500);

                List <Testing.Plumbing.Message> unackedMessages = this.Broker.GetMessages(this.VhostName, "Receiver.boo", 10, false);

                unackedMessages.Should().HaveCount(0);

                List <Testing.Plumbing.Message> brokenMessages = this.Broker.GetMessages(this.VhostName, "all.broken", 10, false);

                brokenMessages.Should().HaveCount(c => c > 0);
            }
            public void should_keep_in_queue()
            {
                IBus producer = this.StartBus(
                    "producer",
                    cfg => cfg.Route("foo")
                    .ConfiguredWith(rrb => rrb.Topology.Declare(Exchange.Named("all.in"))));

                bool wrongHandler = false;

                IBus consumer = this.StartBus(
                    "consumer",
                    cfg =>
                {
                    cfg.OnUnhandled(d => d.Reject(true));

                    cfg.On <BooMessage>("boo")
                    .ReactWith((m, ctx) => { wrongHandler = true; })
                    .RequiresAccept()
                    .WithEndpoint(
                        b =>
                    {
                        Exchange e = b.Topology.Declare(Exchange.Named("all.in"));
                        Queue q    = b.Topology.Declare(Queue.Named("all.in"));
                        b.Topology.Bind(e, q);
                        return(new SubscriptionEndpoint(q, e));
                    });
                });

                producer.Emit("foo", new FooMessage(13));
                producer.Emit("foo", new FooMessage(13));
                producer.Emit("foo", new FooMessage(13));

                consumer.Shutdown();

                Thread.Sleep(500);

                List <Testing.Plumbing.Message> unackedMessages =
                    this.Broker.GetMessages(this.VhostName, "all.in", 10, false);

                unackedMessages.Should().HaveCount(c => c > 0);

                wrongHandler.Should().BeFalse();
            }
예제 #6
0
        /// <summary>
        /// Создает временную конечную точку подписки на сообщения.
        /// Обычно используется для организации варианта коммуникации: запрос-ответ.
        /// </summary>
        /// <returns>
        /// Конечная точка подписки на сообщения <see cref="ISubscriptionEndpoint"/>.
        /// </returns>
        public ISubscriptionEndpoint BuildTempReplyEndpoint()
        {
            var queue = new Queue(this.rabbitChannel.DeclareDefaultQueue());

            return new SubscriptionEndpoint(queue, new StaticRouteResolver(string.Empty, queue.Name));
        }
예제 #7
0
 /// <summary>
 /// Привязывает точку обмена (маршрутизации) с очередью.
 /// </summary>
 /// <param name="exchange">
 /// Точка обмена (маршрутизации) сообщений, на которую поступают сообщения. Точка обмена действует на основе ключа маршрутизации <paramref name="routingKey"/>.
 /// </param>
 /// <param name="queue">
 /// Очередь, в которую будут поступать сообщения из маршрутизатора.
 /// </param>
 /// <param name="routingKey">
 /// Ключ маршрутизации, используется для определения очереди, в которую должно быть отправлено сообщение.
 /// </param>
 public void Bind(Exchange exchange, Queue queue, string routingKey = "")
 {
     this.rabbitChannel.Bind(queue, exchange, routingKey);
 }
예제 #8
0
 /// <summary>
 /// The bind.
 /// </summary>
 /// <param name="topology">
 /// The topology.
 /// </param>
 /// <param name="exchange">
 /// The exchange.
 /// </param>
 /// <param name="queue">
 /// The queue.
 /// </param>
 /// <param name="routingKey">
 /// The routing key.
 /// </param>
 public static void Bind(this ITopologyBuilder topology, Exchange exchange, Queue queue, string routingKey = "")
 {
     ((TopologyBuilder)topology).Bind(exchange, queue, routingKey);
 }
예제 #9
0
        /// <summary>
        /// The declare.
        /// </summary>
        /// <param name="queue">
        /// The queue.
        /// </param>
        public void Declare(Queue queue)
        {
            var arguments = new Dictionary<string, object>();
            if (queue.Ttl.HasValue)
            {
                arguments.Add(Headers.QueueMessageTtl, (long)queue.Ttl.Value.TotalMilliseconds);
            }

            this.SafeNativeInvoke(n => n.QueueDeclare(queue.Name, queue.Durable, queue.Exclusive, queue.AutoDelete, arguments));
        }
예제 #10
0
 /// <summary>
 /// The bind.
 /// </summary>
 /// <param name="queue">
 /// The queue.
 /// </param>
 /// <param name="exchange">
 /// The exchange.
 /// </param>
 /// <param name="routingKey">
 /// The routing key.
 /// </param>
 public void Bind(Queue queue, Exchange exchange, string routingKey)
 {
     this.SafeNativeInvoke(n => n.QueueBind(queue.Name, exchange.Name, routingKey));
 }
예제 #11
0
파일: Queue.cs 프로젝트: ehramovich/Contour
 /// <summary>
 /// Выполняет сравнение двух очередей.
 /// </summary>
 /// <param name="other">
 /// Сравниваемая очередь.
 /// </param>
 /// <returns>
 /// <c>true</c> - если объекты равны, иначе <c>false</c>.
 /// </returns>
 protected bool Equals(Queue other)
 {
     return string.Equals(this.Name, other.Name);
 }