public async Task Should_Be_Able_To_Get_Message_When_Batch_Size_Is_Smaller_Than_Queue_Length() { using (var client = ZyRabbitFactory.CreateTestClient()) { /* Setup */ var message = new BasicMessage { Prop = "Get me, get it?" }; var conventions = new NamingConventions(); var exchangeName = conventions.ExchangeNamingConvention(message.GetType()); TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null); TestChannel.ExchangeDeclare(conventions.ExchangeNamingConvention(message.GetType()), ExchangeType.Topic); TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), conventions.ExchangeNamingConvention(message.GetType()), conventions.RoutingKeyConvention(message.GetType()) + ".#"); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); /* Test */ var ackable = await client.GetManyAsync <BasicMessage>(2); TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType())); TestChannel.ExchangeDelete(exchangeName); /* Assert */ Assert.NotNull(ackable); Assert.Equal(ackable.Content.Count, 2); } }
public async Task Should_Be_Able_To_Ack_Messages_And_Then_Full_List() { using (var client = ZyRabbitFactory.CreateTestClient()) { /* Setup */ var message = new BasicMessage { Prop = "Get me, get it?" }; var conventions = new NamingConventions(); var exchangeName = conventions.ExchangeNamingConvention(message.GetType()); TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null); TestChannel.ExchangeDeclare(conventions.ExchangeNamingConvention(message.GetType()), ExchangeType.Topic); TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), exchangeName, conventions.RoutingKeyConvention(message.GetType()) + ".#"); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); /* Test */ var ackable = await client.GetManyAsync <BasicMessage>(3); ackable.Content[1].Ack(); ackable.Ack(); TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType())); TestChannel.ExchangeDelete(exchangeName); /* Assert */ Assert.True(true); } }
public async Task Should_Be_Able_To_Get_BasicGetResult_Message() { using (var client = ZyRabbitFactory.CreateTestClient()) { /* Setup */ var message = new BasicMessage { Prop = "Get me, get it?" }; var conventions = new NamingConventions(); var exchangeName = conventions.ExchangeNamingConvention(message.GetType()); var queueName = conventions.QueueNamingConvention(message.GetType()); TestChannel.QueueDeclare(queueName, true, false, false, null); TestChannel.ExchangeDeclare(exchangeName, ExchangeType.Topic); TestChannel.QueueBind(queueName, exchangeName, conventions.RoutingKeyConvention(message.GetType()) + ".#"); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); /* Test */ var ackable = await client.GetAsync(cfg => cfg.FromQueue(queueName)); /* Assert */ Assert.NotNull(ackable); Assert.NotEmpty(ackable.Content.Body); TestChannel.QueueDelete(queueName); TestChannel.ExchangeDelete(exchangeName); } }
public async Task Should_Be_Able_To_Nack_One_In_Batch() { using (var client = ZyRabbitFactory.CreateTestClient()) { /* Setup */ var message = new BasicMessage { Prop = "Get me, get it?" }; var nacked = new BasicMessage { Prop = "Not me! Plz?" }; var conventions = new NamingConventions(); var exchangeName = conventions.ExchangeNamingConvention(message.GetType()); TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null); TestChannel.ExchangeDeclare(exchangeName, ExchangeType.Topic); TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), conventions.ExchangeNamingConvention(message.GetType()), conventions.RoutingKeyConvention(message.GetType()) + ".#"); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(nacked, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); /* Test */ var ackableList = await client.GetManyAsync <BasicMessage>(3); foreach (var ackableMsg in ackableList.Content) { if (string.Equals(ackableMsg.Content.Prop, message.Prop)) { ackableMsg.Ack(); } else { ackableMsg.Nack(); } } var getAgain = await client.GetAsync <BasicMessage>(); TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType())); TestChannel.ExchangeDelete(exchangeName); /* Assert */ Assert.NotNull(getAgain); Assert.Equal(getAgain.Content.Prop, nacked.Prop); } }
public async Task Should_Be_Able_To_Subscribe_Initialized_Queue_And_Exchange() { using (var client = TestClientFactory.CreateNormal()) { /* Setup */ const string exchangeName = "initialized.exchange"; const string queueName = "initialized.queue"; try { TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Fanout); TestChannel.QueueDeclare(queueName, true, false, false); var tcs = new TaskCompletionSource <DynamicMessage>(); client.SubscribeAsync <DynamicMessage>((message, context) => { tcs.TrySetResult(message); return(Task.FromResult(true)); }, cfg => cfg .WithQueue(q => q .AssumeInitialized() .WithName(queueName)) .WithSubscriberId(string.Empty) .WithExchange(e => e .AssumeInitialized() .WithName(exchangeName))); /* Test */ await client.PublishAsync(new DynamicMessage { Body = new { IsDynamic = true } }, configuration : cfg => cfg .WithExchange(e => e .AssumeInitialized() .WithName(exchangeName))); await tcs.Task; /* Assert */ Assert.True(tcs.Task.Result.Body.IsDynamic); } finally { /* Teardown */ TestChannel.QueueDelete(queueName); TestChannel.ExchangeDelete(exchangeName); } } }
public async Task Should_Update_Exhange_Type() { /* Setup */ const string exchangeName = "topology"; TestChannel.ExchangeDelete(exchangeName); TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Direct); var client = RawRabbitFactory.GetExtendableClient() as ExtendableBusClient <MessageContext>; /* Test */ await client.UpdateTopologyAsync(t => t .ForExchange(exchangeName) .UseConfiguration(e => e .WithType(ExchangeType.Topic) .WithDurability(false)) ); /* Assert */ TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Topic); Assert.True(true, "Did not throw"); Assert.Throws <OperationInterruptedException>(() => TestChannel.ExchangeDeclare(exchangeName, RabbitMQ.Client.ExchangeType.Direct)); }