public void TestSendAndReceiveTransactedWithUncachedConnection() { var singleConnectionFactory = new SingleConnectionFactory("localhost"); var template = new RabbitTemplate(singleConnectionFactory) { IsChannelTransacted = true }; template.ConvertAndSend(ROUTE, "message"); var result = template.ReceiveAndConvert <string>(ROUTE); Assert.Equal("message", result); result = template.ReceiveAndConvert <string>(ROUTE); Assert.Null(result); singleConnectionFactory.Destroy(); }
public void TestNoFailOnStartupWithMissingBroker() { var serviceCollection = new ServiceCollection(); serviceCollection.AddRabbitQueue(new Config.Queue("foo")); var connectionFactory = new SingleConnectionFactory("foo") { Port = 434343 }; var applicationContext = GetApplicationContext(serviceCollection); var rabbitAdmin = new RabbitAdmin(applicationContext, connectionFactory) { AutoStartup = true }; connectionFactory.Destroy(); }
public void TestFailOnFirstUseWithMissingBroker() { var serviceCollection = new ServiceCollection(); serviceCollection.AddRabbitQueue(new Config.Queue("foo")); var connectionFactory = new SingleConnectionFactory("localhost") { Port = 434343 }; var applicationContext = GetApplicationContext(serviceCollection); var rabbitAdmin = new RabbitAdmin(applicationContext, connectionFactory) { AutoStartup = true }; Assert.Throws <AmqpConnectException>(() => rabbitAdmin.DeclareQueue()); connectionFactory.Destroy(); }
public void TestTemporaryLogs() { var serviceCollection = new ServiceCollection(); serviceCollection.AddRabbitQueue(new Config.Queue("testq.nonDur", false, false, false)); serviceCollection.AddRabbitQueue(new Config.Queue("testq.ad", true, false, true)); serviceCollection.AddRabbitQueue(new Config.Queue("testq.excl", true, true, false)); serviceCollection.AddRabbitQueue(new Config.Queue("testq.all", false, true, true)); serviceCollection.AddRabbitExchange(new Config.DirectExchange("testex.nonDur", false, false)); serviceCollection.AddRabbitExchange(new Config.DirectExchange("testex.ad", true, true)); serviceCollection.AddRabbitExchange(new Config.DirectExchange("testex.all", false, true)); var connectionFactory = new SingleConnectionFactory("localhost"); var applicationContext = GetApplicationContext(serviceCollection); var logs = new List <string>(); var mockLogger = new Mock <ILogger>(); mockLogger.Setup((l) => l.Log(It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <It.IsAnyType>(), It.IsAny <Exception>(), (Func <It.IsAnyType, Exception, string>)It.IsAny <object>())) .Callback(new InvocationAction(invocation => { logs.Add(invocation.Arguments[2].ToString()); })); var rabbitAdmin = new RabbitAdmin(applicationContext, connectionFactory, mockLogger.Object); try { connectionFactory.CreateConnection().Close(); logs.Sort(); Assert.NotEmpty(logs); Assert.Contains("(testex.ad) durable:True, auto-delete:True", logs[0]); Assert.Contains("(testex.all) durable:False, auto-delete:True", logs[1]); Assert.Contains("(testex.nonDur) durable:False, auto-delete:False", logs[2]); Assert.Contains("(testq.ad) durable:True, auto-delete:True, exclusive:False", logs[3]); Assert.Contains("(testq.all) durable:False, auto-delete:True, exclusive:True", logs[4]); Assert.Contains("(testq.excl) durable:True, auto-delete:False, exclusive:True", logs[5]); Assert.Contains("(testq.nonDur) durable:False, auto-delete:False, exclusive:False", logs[6]); } finally { CleanQueuesAndExchanges(rabbitAdmin); connectionFactory.Destroy(); } }
public async Task TestGetQueueProperties() { var serviceCollection = new ServiceCollection(); var connectionFactory = new SingleConnectionFactory("localhost"); var applicationContext = GetApplicationContext(serviceCollection); var rabbitAdmin = new RabbitAdmin(applicationContext, connectionFactory); var queueName = "test.properties." + DateTimeOffset.Now.ToUnixTimeMilliseconds(); try { rabbitAdmin.DeclareQueue(new Config.Queue(queueName)); var template = new RabbitTemplate(connectionFactory); template.ConvertAndSend(queueName, "foo"); var n = 0; while (n++ < 100 && MessageCount(rabbitAdmin, queueName) == 0) { await Task.Delay(100); } Assert.True(n < 100); var channel = connectionFactory.CreateConnection().CreateChannel(false); var consumer = new DefaultBasicConsumer(channel); channel.BasicConsume(queueName, true, consumer); n = 0; while (n++ < 100 && MessageCount(rabbitAdmin, queueName) > 0) { await Task.Delay(100); } Assert.True(n < 100); var props = rabbitAdmin.GetQueueProperties(queueName); Assert.True(props.TryGetValue(RabbitAdmin.QUEUE_CONSUMER_COUNT, out var consumerCount)); Assert.Equal(1U, consumerCount); channel.Close(); } finally { rabbitAdmin.DeleteQueue(queueName); connectionFactory.Destroy(); } }