static void Main(string[] args) { Console.WriteLine("Iniciando aplicação"); try { ILoggerFactory factory = new LoggerFactory(); var settings = GetConfiguration(); IBuilder builder = new AmqpBuilder(settings, factory); using (var manager = new MessagingManager(builder, factory)) { var publisher = builder.BuildPublisher(); manager.LoadProcessors(null); manager.Start(); Console.WriteLine("[.] Publicando mensagem para [testQueue123] ..."); publisher.Publish(new ExampleMessage() { Text = "It's working" }, "testQueue123"); Console.WriteLine("Rodando aplicação. Pressione (enter) para encerrar."); Console.ReadLine(); manager.Stop(); Console.WriteLine("Aplicação encerrada com sucesso."); } } catch (Exception err) { Console.WriteLine($"Erro ao executar aplicação. Detalhes: ${err.Message}"); } }
public void CreateBuilderWithoutConnectionFactoryTest() { var settings = new Mock <IConfiguration>(); settings.Setup(s => s.GetSection("RABBIT_URL")) .Returns(GetMockConfigSection("amqp://invalidhost")); settings.Setup(s => s.GetSection("RABBIT_API_URL")) .Returns(GetMockConfigSection("http://*****:*****@locahost")); Assert.Throws <BrokerUnreachableException>(() => builder = new AmqpBuilder(settings.Object, loggerFactoryMock.Object, null)); }
public void CreateBuilderWithUserAndPasswordForApiTest() { var settings = new Mock <IConfiguration>(); settings.Setup(s => s.GetSection("RABBIT_URL")) .Returns(GetMockConfigSection("amqp://localhost")); settings.Setup(s => s.GetSection("RABBIT_API_URL")) .Returns(GetMockConfigSection("http://*****:*****@locahost")); builder = new AmqpBuilder(settings.Object, loggerFactoryMock.Object, connectionFactoryMock.Object); var manager = builder.BuildAPIManager(); Assert.IsType <RabbitMQApiManager>(manager); }
static void Main(string[] args) { Console.WriteLine("Iniciando aplicação"); try { ILoggerFactory factory = new LoggerFactory(); IBuilder builder = new AmqpBuilder(GetConfiguration(), factory); var manager = new MessagingManager(builder, factory); var publisher = builder.BuildPublisher(); manager.LoadProcessors(null); manager.Start(); Console.WriteLine("[.] Publicando mensagem para [testQueue123] ..."); Console.WriteLine("Rodando aplicação. Digite (quit) para encerrar ou qualquer numero apra calcular Fibonacci."); while (true) { var value = Console.ReadLine(); if (value == "quit") { break; } if (!Int32.TryParse(value, out int fibNum)) { Console.WriteLine($"{value} não é um inteiro válido"); } var reply = publisher.PublishAndWait <FibMessage>(new FibMessage() { Number = fibNum }, "test.fibonacci").Result; if (String.IsNullOrEmpty(reply.ErrorMessage)) { Console.WriteLine($"Fibonacci para {fibNum} é igual a {reply.Number}"); } else { Console.WriteLine($"Erro ao calcular fibonacci: {reply.ErrorMessage}"); } } manager.Stop(); Console.WriteLine("Aplicação encerrada com sucesso."); } catch (Exception err) { Console.WriteLine($"Erro ao executar aplicação. Detalhes: ${err.Message}"); } }
public AmqpBuilderTests() { loggerFactoryMock = new Mock <ILoggerFactory>(); loggerFactoryMock.Setup(l => l.CreateLogger(It.IsAny <string>())) .Returns(new Mock <ILogger <AmqpBuilder> >().Object); connectionMock = new Mock <IConnection>(); connectionFactoryMock = new Mock <IConnectionFactory>(); connectionFactoryMock.Setup(c => c.CreateConnection()) .Returns(connectionMock.Object); var settings = new Mock <IConfiguration>(); settings.Setup(s => s.GetSection("RABBIT_URL")) .Returns(GetMockConfigSection("amqp://localhost")); settings.Setup(s => s.GetSection("RABBIT_API_URL")) .Returns(GetMockConfigSection("http://locahost")); builder = new AmqpBuilder(settings.Object, loggerFactoryMock.Object, connectionFactoryMock.Object); }