예제 #1
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();
            }
예제 #2
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);
            }
예제 #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);
 }