public static Named ( string name ) : |
||
name | string | /// Имя создаваемой очереди. /// |
Résultat |
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(); }
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); }
/// <summary> /// Создает временную конечную точку для получения сообщений. /// </summary> /// <param name="endpoint">Конечная точка шины сообщений для который создается подписка.</param> /// <param name="label">Метка сообщений, на которые ожидается получение ответа.</param> /// <returns> /// Конечная точка подписки для получения сообщений. /// </returns> public ISubscriptionEndpoint BuildTempReplyEndpoint(IEndpoint endpoint, MessageLabel label) { var queue = Queue.Named(string.Format("{0}.replies-{1}-{2}", endpoint.Address, label.IsAny ? "any" : label.Name, NameGenerator.GetRandomName(8))) .AutoDelete.Exclusive.Instance; this.rabbitChannel.Declare(queue); return(new SubscriptionEndpoint(queue, new StaticRouteResolver(string.Empty, queue.Name))); }
/// <summary> /// Создает временную конечную точку для получения сообщений. /// </summary> /// <param name="endpoint">Конечная точка шины сообщений для который создается подписка.</param> /// <param name="label">Метка сообщений, на которые ожидается получение ответа.</param> /// <returns> /// Конечная точка подписки для получения сообщений. /// </returns> public ISubscriptionEndpoint BuildTempReplyEndpoint(IEndpoint endpoint, MessageLabel label) { using (var channel = (RabbitChannel)this.channelProvider.OpenChannel(CancellationToken.None)) { var queue = Queue.Named( $"{endpoint.Address}.replies-{(label.IsAny ? "any" : label.Name)}-{NameGenerator.GetRandomName(8)}") .AutoDelete.Exclusive.Instance; channel.Declare(queue); return(new SubscriptionEndpoint(queue, new StaticRouteResolver(string.Empty, queue.Name))); } }
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(); }