public void Should_register_for_publisher_confirms() { var task = publisherConfirms.PublishWithConfirm(channel, model => { }); channel.Raise(x => x.BasicAcks += null, null, new BasicAckEventArgs()); task.Wait(); channel.AssertWasCalled(x => x.ConfirmSelect()); }
// -------------------------------- publish --------------------------------------------- public virtual Task PublishAsync( IExchange exchange, string routingKey, bool mandatory, bool immediate, MessageProperties messageProperties, byte[] body) { Preconditions.CheckNotNull(exchange, "exchange"); Preconditions.CheckShortString(routingKey, "routingKey"); Preconditions.CheckNotNull(messageProperties, "messageProperties"); Preconditions.CheckNotNull(body, "body"); var task = clientCommandDispatcher.Invoke(x => { var properties = x.CreateBasicProperties(); messageProperties.CopyTo(properties); return(publisherConfirms.PublishWithConfirm(x, m => m.BasicPublish(exchange.Name, routingKey, mandatory, immediate, properties, body))); }).Unwrap(); logger.DebugWrite("Published to exchange: '{0}', routing key: '{1}', correlationId: '{2}'", exchange.Name, routingKey, messageProperties.CorrelationId); return(task); }
public void Should_complete_task_immediately_without_waiting_for_ack() { var taskWasExecuted = false; var task = publisherConfirms.PublishWithConfirm(channel, model => taskWasExecuted = true); task.Wait(); taskWasExecuted.ShouldBeTrue(); }
public void Should_complete_task_when_new_model_acks() { var channel1 = MockRepository.GenerateStub <IModel>(); var channel2 = MockRepository.GenerateStub <IModel>(); var modelsUsedInPublish = new List <IModel>(); // do the publish, this should be retried against the new model after it reconnects. var task = publisherConfirms.PublishWithConfirm(channel1, modelsUsedInPublish.Add); // new channel connects eventBus.Publish(new PublishChannelCreatedEvent(channel2)); // new channel ACKs (sequence number is 0) channel2.Raise(x => x.BasicAcks += null, null, new BasicAckEventArgs()); // wait for task to complete task.Wait(); // should have published on both channels: modelsUsedInPublish.Count.ShouldEqual(2); modelsUsedInPublish[0].ShouldBeTheSameAs(channel1); modelsUsedInPublish[1].ShouldBeTheSameAs(channel2); }