Skip to content

Commit

Permalink
Update to the latest code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ifgris committed Jul 7, 2024
1 parent f81fc84 commit d703c24
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 82 deletions.
32 changes: 16 additions & 16 deletions Example/Example.Autofac/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FooQueueHandler>("FooConsumer", consumers: 3)
Expand Down
32 changes: 16 additions & 16 deletions Example/Example.MultiConnections/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultMessageHandler>("DefaultRabbitHelper", "DefaultFooConsumer");

Expand All @@ -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<DefaultMessageHandler>("TestRabbitHelper", "TestFooConsumer");

Expand Down
55 changes: 35 additions & 20 deletions Example/Example.NLog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FooQueueHandler>("FooConsumer", consumers: 3)
Expand All @@ -80,20 +81,34 @@ IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)

public class FooQueueHandler : DefaultMessageHandler
{
private readonly ILogger<FooQueueHandler> _logger;

public FooQueueHandler(ILogger<FooQueueHandler> 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<BarQueueHandler> _logger;

public BarQueueHandler(ILogger<BarQueueHandler> 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");
}
}
16 changes: 8 additions & 8 deletions Example/Example.ProducerInConsumer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FooQueueHandler>("FooConsumer", consumers: 3);
Expand Down
22 changes: 11 additions & 11 deletions Example/Example.RabbitAsyncConsumer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FooQueueHandler>("FooConsumer", consumers: 3)
Expand Down
22 changes: 11 additions & 11 deletions Example/Example.SimpleDI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FooQueueHandler>("FooConsumer", consumers: 3)
Expand Down

0 comments on commit d703c24

Please sign in to comment.