refactor: 重构RabbitMQ消费者体系,新增自动铺码功能
1. 新增AutoDotCodeConsumer自动铺码消费者,实现统一的交换机路由绑定 2. 重构RabbitMQ接收方法,支持交换机、路由键配置,添加死信队列处理 3. 重构现有JournalTaskReceiveConsumer,使用标准交换机路由配置 4. 更新JournalPageService,将打印逻辑替换为自动铺码消息发送 5. 调整枚举类型,重构任务类型命名 6. 更新实体和DTO,新增Prompt相关字段 7. 添加PrintToolV2.7配套工具和文档 8. 清理冗余的PrintJournalPageAsync接口
This commit is contained in:
@ -26,18 +26,17 @@ namespace QYZH.InteractiveMagazine.Infrastructure.RabbitMQ
|
||||
{
|
||||
using var channel = await _connection.CreateChannel();
|
||||
|
||||
// 启用发布者确认
|
||||
//var channelOpts = new CreateChannelOptions
|
||||
//(
|
||||
// publisherConfirmationsEnabled: true,
|
||||
// publisherConfirmationTrackingEnabled: true,
|
||||
// outstandingPublisherConfirmationsRateLimiter: new ThrottlingRateLimiter(MAX_OUTSTANDING_CONFIRMS)
|
||||
//);
|
||||
// 声明 Exchange(持久化)
|
||||
await channel.ExchangeDeclareAsync(exchange: param.Exchange, type: "direct", durable: true, autoDelete: false, arguments: null);
|
||||
|
||||
// 声明队列(持久化)
|
||||
await channel.QueueDeclareAsync(queue: param.RoutingKey, durable: true, exclusive: false, autoDelete: false, arguments: null);
|
||||
await channel.QueueDeclareAsync(queue: param.Queue, durable: true, exclusive: false, autoDelete: false, arguments: null);
|
||||
|
||||
// 绑定队列到 Exchange
|
||||
await channel.QueueBindAsync(queue: param.Queue, exchange: param.Exchange, routingKey: param.RoutingKey, arguments: null);
|
||||
|
||||
// 清空队列
|
||||
if (param.Purge) await channel.QueuePurgeAsync(param.RoutingKey);
|
||||
if (param.Purge) await channel.QueuePurgeAsync(param.Queue);
|
||||
// 消息序列化
|
||||
var mesjson = JsonSerializer.Serialize(param.Data, options);
|
||||
|
||||
@ -128,12 +127,20 @@ namespace QYZH.InteractiveMagazine.Infrastructure.RabbitMQ
|
||||
}
|
||||
|
||||
|
||||
public async Task ReceiveAsync(string queueName, Func<IChannel, BasicDeliverEventArgs, Task> callback, CancellationToken cancellationToken = default)
|
||||
public async Task ReceiveAsync(string exchange, string queueName, string routingKey, Func<IChannel, BasicDeliverEventArgs, Task> callback, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var channel = await _connection.CreateChannel();
|
||||
//await channel.BasicQosAsync(0, 10, false); // 一次最多接收10条未确认的消息
|
||||
|
||||
// 声明 Exchange(持久化)
|
||||
await channel.ExchangeDeclareAsync(exchange: exchange, type: "direct", durable: true, autoDelete: false, arguments: null);
|
||||
|
||||
// 声明队列(持久化)
|
||||
await channel.QueueDeclareAsync(queue: queueName, durable: true, exclusive: false, autoDelete: false, arguments: null);
|
||||
|
||||
// 绑定队列到 Exchange
|
||||
await channel.QueueBindAsync(queue: queueName, exchange: exchange, routingKey: routingKey, arguments: null);
|
||||
|
||||
var consumer = new AsyncEventingBasicConsumer(channel);
|
||||
consumer.ReceivedAsync += async (model, ea) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user