Esempio n. 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);
            }
Esempio n. 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();
            }
Esempio n. 3
0
 /// <summary>
 /// Инициализирует новый экземпляр класса <see cref="StaticRouteResolver"/>.
 /// </summary>
 /// <param name="exchange">
 /// The exchange.
 /// </param>
 /// <param name="routingKey">
 /// The routing key.
 /// </param>
 public StaticRouteResolver(Exchange exchange, string routingKey = "")
     : this(exchange.Name, routingKey)
 {
 }
Esempio n. 4
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);
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
 /// <summary>
 /// The declare.
 /// </summary>
 /// <param name="exchange">
 /// The exchange.
 /// </param>
 public void Declare(Exchange exchange)
 {
     this.SafeNativeInvoke(n => n.ExchangeDeclare(exchange.Name, exchange.Type, exchange.Durable, exchange.AutoDelete, new Dictionary<string, object>()));
 }
Esempio n. 7
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));
 }
Esempio n. 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);
 }
Esempio n. 9
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);
 }