diff --git a/Example/Example.Autofac/Program.cs b/Example/Example.Autofac/Program.cs index fad4fa8..3f829f3 100644 --- a/Example/Example.Autofac/Program.cs +++ b/Example/Example.Autofac/Program.cs @@ -32,29 +32,29 @@ IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) builder.SetVirtualHost("/"); builder.SetUserName("admin"); builder.SetPassword("admin"); - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "FooProducer", - ExchangeName = "amq.topic", - RoutingKey = "foo.key", - Type = ExchangeType.Topic + producer.ProducerName = "FooProducer"; + producer.ExchangeName = "amq.topic"; + producer.RoutingKey = "foo.key"; + producer.Type = ExchangeType.Topic; }); - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "BarProducer", - ExchangeName = "amq.direct", - RoutingKey = "bar.key", - Type = ExchangeType.Direct + producer.ProducerName = "BarProducer"; + producer.ExchangeName = "amq.direct"; + producer.RoutingKey = "bar.key"; + producer.Type = ExchangeType.Direct; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "FooConsumer", - QueueName = "foo-queue" + consumer.ConsumerName = "FooConsumer"; + consumer.QueueName = "foo-queue"; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "BarConsumer", - QueueName = "bar-queue" + consumer.ConsumerName = "BarConsumer"; + consumer.QueueName = "bar-queue"; }); }) .AddRabbitConsumer("FooConsumer", consumers: 3) diff --git a/Example/Example.MultiConnections/Program.cs b/Example/Example.MultiConnections/Program.cs index 903a245..4436007 100644 --- a/Example/Example.MultiConnections/Program.cs +++ b/Example/Example.MultiConnections/Program.cs @@ -14,17 +14,17 @@ builder.SetVirtualHost("/"); builder.SetUserName("admin"); builder.SetPassword("admin"); - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "FooProducer", - ExchangeName = "amq.topic", - RoutingKey = "foo.key", - Type = ExchangeType.Topic + producer.ProducerName = "FooProducer"; + producer.ExchangeName = "amq.topic"; + producer.RoutingKey = "foo.key"; + producer.Type = ExchangeType.Topic; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "DefaultFooConsumer", - QueueName = "foo-queue" + consumer.ConsumerName = "DefaultFooConsumer"; + consumer.QueueName = "foo-queue"; }); }).AddKeyedRabbitConsumer("DefaultRabbitHelper", "DefaultFooConsumer"); @@ -35,17 +35,17 @@ builder.SetVirtualHost("test"); builder.SetUserName("admin"); builder.SetPassword("admin"); - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "FooProducer", - ExchangeName = "amq.topic", - RoutingKey = "foo.key", - Type = ExchangeType.Topic + producer.ProducerName = "FooProducer"; + producer.ExchangeName = "amq.topic"; + producer.RoutingKey = "foo.key"; + producer.Type = ExchangeType.Topic; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "TestFooConsumer", - QueueName = "foo-queue" + consumer.ConsumerName = "TestFooConsumer"; + consumer.QueueName = "foo-queue"; }); }).AddKeyedRabbitConsumer("TestRabbitHelper", "TestFooConsumer"); diff --git a/Example/Example.NLog/Program.cs b/Example/Example.NLog/Program.cs index 7faa1e1..ee1ba11 100644 --- a/Example/Example.NLog/Program.cs +++ b/Example/Example.NLog/Program.cs @@ -46,29 +46,30 @@ IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) builder.SetVirtualHost("/"); builder.SetUserName("admin"); builder.SetPassword("admin"); - builder.AddProducer(new ProducerOptions + builder.EnableLogging(false); + builder.AddProducer(producer => { - ProducerName = "FooProducer", - ExchangeName = "amq.topic", - RoutingKey = "foo.key", - Type = ExchangeType.Topic + producer.ProducerName = "FooProducer"; + producer.ExchangeName = "amq.topic"; + producer.RoutingKey = "foo.key"; + producer.Type = ExchangeType.Topic; }); - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "BarProducer", - ExchangeName = "amq.direct", - RoutingKey = "bar.key", - Type = ExchangeType.Direct + producer.ProducerName = "BarProducer"; + producer.ExchangeName = "amq.direct"; + producer.RoutingKey = "bar.key"; + producer.Type = ExchangeType.Direct; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "FooConsumer", - QueueName = "foo-queue" + consumer.ConsumerName = "FooConsumer"; + consumer.QueueName = "foo-queue"; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "BarConsumer", - QueueName = "bar-queue" + consumer.ConsumerName = "BarConsumer"; + consumer.QueueName = "bar-queue"; }); }) .AddRabbitConsumer("FooConsumer", consumers: 3) @@ -80,20 +81,34 @@ IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) public class FooQueueHandler : DefaultMessageHandler { + private readonly ILogger _logger; + + public FooQueueHandler(ILogger logger) + { + _logger = logger; + } + public override void HandleMessage(string message) { - Console.WriteLine($"[x] Received from foo-queue: {message}"); + _logger.LogInformation($"[x] Received from foo-queue: {message}"); Task.Delay(1000).Wait(); - Console.WriteLine("[x] Done"); + _logger.LogInformation("[x] Done"); } } public class BarQueueHandler : DefaultMessageHandler { + private readonly ILogger _logger; + + public BarQueueHandler(ILogger logger) + { + _logger = logger; + } + public override void HandleMessage(string message) { - Console.WriteLine($"[x] Received from bar-queue: {message}"); + _logger.LogInformation($"[x] Received from bar-queue: {message}"); Task.Delay(500).Wait(); - Console.WriteLine("[x] Done"); + _logger.LogInformation("[x] Done"); } } \ No newline at end of file diff --git a/Example/Example.ProducerInConsumer/Program.cs b/Example/Example.ProducerInConsumer/Program.cs index 93db2d8..47f37b9 100644 --- a/Example/Example.ProducerInConsumer/Program.cs +++ b/Example/Example.ProducerInConsumer/Program.cs @@ -13,17 +13,17 @@ builder.SetVirtualHost("/"); builder.SetUserName("admin"); builder.SetPassword("admin"); - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "BarProducer", - ExchangeName = "amq.direct", - RoutingKey = "bar.key", - Type = ExchangeType.Direct + producer.ProducerName = "BarProducer"; + producer.ExchangeName = "amq.direct"; + producer.RoutingKey = "bar.key"; + producer.Type = ExchangeType.Direct; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "FooConsumer", - QueueName = "foo-queue" + consumer.ConsumerName = "FooConsumer"; + consumer.QueueName = "foo-queue"; }); }) .AddRabbitConsumer("FooConsumer", consumers: 3); diff --git a/Example/Example.RabbitAsyncConsumer/Program.cs b/Example/Example.RabbitAsyncConsumer/Program.cs index 66a7040..60a74b0 100644 --- a/Example/Example.RabbitAsyncConsumer/Program.cs +++ b/Example/Example.RabbitAsyncConsumer/Program.cs @@ -13,22 +13,22 @@ builder.SetUserName("admin"); builder.SetPassword("admin"); builder.UseAsyncConsumer(true); // set UseAsyncConsumer to true - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "FooProducer", - ExchangeName = "amq.topic", - RoutingKey = "foo.key", - Type = ExchangeType.Topic + producer.ProducerName = "FooProducer"; + producer.ExchangeName = "amq.topic"; + producer.RoutingKey = "foo.key"; + producer.Type = ExchangeType.Topic; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "FooConsumer", - QueueName = "foo-queue" + consumer.ConsumerName = "FooConsumer"; + consumer.QueueName = "foo-queue"; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "BarConsumer", - QueueName = "bar-queue" + consumer.ConsumerName = "BarConsumer"; + consumer.QueueName = "bar-queue"; }); }) .AddAsyncRabbitConsumer("FooConsumer", consumers: 3) diff --git a/Example/Example.SimpleDI/Program.cs b/Example/Example.SimpleDI/Program.cs index 4fe1f8e..906a0b7 100644 --- a/Example/Example.SimpleDI/Program.cs +++ b/Example/Example.SimpleDI/Program.cs @@ -18,22 +18,22 @@ static void Main(string[] args) builder.SetUserName("admin"); builder.SetPassword("admin"); builder.EnableLogging(true); - builder.AddProducer(new ProducerOptions + builder.AddProducer(producer => { - ProducerName = "FooProducer", - ExchangeName = "amq.topic", - RoutingKey = "foo.key", - Type = ExchangeType.Topic + producer.ProducerName = "FooProducer"; + producer.ExchangeName = "amq.topic"; + producer.RoutingKey = "foo.key"; + producer.Type = ExchangeType.Topic; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "FooConsumer", - QueueName = "foo-queue" + consumer.ConsumerName = "FooConsumer"; + consumer.QueueName = "foo-queue"; }); - builder.AddConsumer(new ConsumerOptions + builder.AddConsumer(consumer => { - ConsumerName = "BarConsumer", - QueueName = "bar-queue" + consumer.ConsumerName = "BarConsumer"; + consumer.QueueName = "bar-queue"; }); }) .AddRabbitConsumer("FooConsumer", consumers: 3)