使用 Azure 服务总线的公共交通:为什么消息会发送到 queue_skipped?
Masstransit with azure service bus: Why Messages go to the queue_skipped?
我正在将 Masstransit 与 Azure 服务 .net5 结合使用。
我有两个申请:
网络Api。启动:
services.AddMassTransit(x =>
{
x.UsingAzureServiceBus((context,cfg) =>
{
cfg.Host("Endpoint");
cfg.ReceiveEndpoint("mytopic", e =>
{
e.PrefetchCount = 100;
e.MaxConcurrentCalls = 100;
});
cfg.ConfigureEndpoints(context);
});
});
services.AddMassTransitHostedService();
网络Api。事件发布控制器:
[HttpGet]
public async Task<bool> Get()
{
await _bus.Publish(new Message()
{
Name = "Test Name",
Description = "Test Description",
Order = 1
});
return true;
}
工人服务。程序:
services.AddMassTransit(x =>
{
x.AddConsumer<MessageConsumer>();
x.UsingAzureServiceBus((context,cfg) =>
{
cfg.Host("Endpoint");
cfg.UseServiceBusMessageScheduler();
cfg.ReceiveEndpoint("mytopic", e =>
{
e.PrefetchCount = 100;
e.MaxConcurrentCalls = 100;
e.ConfigureConsumer<MessageConsumer>(context);
});
cfg.ConfigureEndpoints(context);
});
});
services.AddMassTransitHostedService(true);
工人服务。消费者:
public class MessageConsumer : IConsumer<Message>
{
readonly ILogger<MessageConsumer> _logger;
public MessageConsumer(ILogger<MessageConsumer> logger)
{
_logger = logger;
}
public async Task Consume(ConsumeContext<Message> context)
{
_logger.LogInformation("Received Text: {Text}", context.Message.Name);
}
}
两个应用程序都有事件 class(代码中的消息 class),它们在同一个命名空间中。
namespace EventBusMessages
{
public class Message
{
public string Name { get; set; }
public string Description { get; set; }
public int Order { get; set; }
}
}
成功发送和处理一条消息后,下一条消息将放入队列 ***_skipped。然后下一条消息再次成功处理,但随后再次 ***_skipped。
发布控制台示例:
[05:26:19 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-df61-08d92e12a05d EventBusMessages.
Message
[05:26:20 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-216c-08d92e12a182 EventBusMessages.
Message
[05:26:20 DBG] SKIP sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-216c-08d92e12a182
[05:26:21 INF] MOVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-216c-08d92e12a182 mytopic_skipped dead-letter
[05:26:22 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-fc4d-08d92e12a27a EventBusMessages.
Message
[05:26:23 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-d1a8-08d92e12a30b EventBusMessages.
Message
[05:26:23 DBG] SKIP sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-d1a8-08d92e12a30b
[05:26:23 INF] MOVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-d1a8-08d92e12a30b mytopic_skipped dead-letter
05:26:19 和 05:26:22 已被消费者成功处理,但 05:26:20 和 05:26:23
已被跳过并移至 ***_skipped 队列
消费者控制台示例:
[05:26:19 DBG] RECEIVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-df61-08d92e12a05d EventBusMessages.Message EventB
usSubscriber.MessageConsumer(00:00:00.0126036)
[05:26:22 INF] Received Text: Test Name
[05:26:22 DBG] RECEIVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-fc4d-08d92e12a27a EventBusMessages.Message EventB
usSubscriber.MessageConsumer(00:00:00.0042202)
同样,我每次都发送相同的消息
谢谢你的回答
Web API 项目不应该有接收端点——它没有配置消费者。因此,该接收端点将跳过每条消息。只有在有消费者时才配置接收端点。
并且您只需在添加消费者后调用 ConfigureEndpoints
。
我正在将 Masstransit 与 Azure 服务 .net5 结合使用。
我有两个申请:
网络Api。启动:
services.AddMassTransit(x =>
{
x.UsingAzureServiceBus((context,cfg) =>
{
cfg.Host("Endpoint");
cfg.ReceiveEndpoint("mytopic", e =>
{
e.PrefetchCount = 100;
e.MaxConcurrentCalls = 100;
});
cfg.ConfigureEndpoints(context);
});
});
services.AddMassTransitHostedService();
网络Api。事件发布控制器:
[HttpGet]
public async Task<bool> Get()
{
await _bus.Publish(new Message()
{
Name = "Test Name",
Description = "Test Description",
Order = 1
});
return true;
}
工人服务。程序:
services.AddMassTransit(x =>
{
x.AddConsumer<MessageConsumer>();
x.UsingAzureServiceBus((context,cfg) =>
{
cfg.Host("Endpoint");
cfg.UseServiceBusMessageScheduler();
cfg.ReceiveEndpoint("mytopic", e =>
{
e.PrefetchCount = 100;
e.MaxConcurrentCalls = 100;
e.ConfigureConsumer<MessageConsumer>(context);
});
cfg.ConfigureEndpoints(context);
});
});
services.AddMassTransitHostedService(true);
工人服务。消费者:
public class MessageConsumer : IConsumer<Message>
{
readonly ILogger<MessageConsumer> _logger;
public MessageConsumer(ILogger<MessageConsumer> logger)
{
_logger = logger;
}
public async Task Consume(ConsumeContext<Message> context)
{
_logger.LogInformation("Received Text: {Text}", context.Message.Name);
}
}
两个应用程序都有事件 class(代码中的消息 class),它们在同一个命名空间中。
namespace EventBusMessages
{
public class Message
{
public string Name { get; set; }
public string Description { get; set; }
public int Order { get; set; }
}
}
成功发送和处理一条消息后,下一条消息将放入队列 ***_skipped。然后下一条消息再次成功处理,但随后再次 ***_skipped。
发布控制台示例:
[05:26:19 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-df61-08d92e12a05d EventBusMessages.
Message
[05:26:20 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-216c-08d92e12a182 EventBusMessages.
Message
[05:26:20 DBG] SKIP sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-216c-08d92e12a182
[05:26:21 INF] MOVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-216c-08d92e12a182 mytopic_skipped dead-letter
[05:26:22 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-fc4d-08d92e12a27a EventBusMessages.
Message
[05:26:23 DBG] SEND sb://test.servicebus.windows.net/EventBusMessages/Message c7710000-e64a-00ff-d1a8-08d92e12a30b EventBusMessages.
Message
[05:26:23 DBG] SKIP sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-d1a8-08d92e12a30b
[05:26:23 INF] MOVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-d1a8-08d92e12a30b mytopic_skipped dead-letter
05:26:19 和 05:26:22 已被消费者成功处理,但 05:26:20 和 05:26:23 已被跳过并移至 ***_skipped 队列
消费者控制台示例:
[05:26:19 DBG] RECEIVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-df61-08d92e12a05d EventBusMessages.Message EventB
usSubscriber.MessageConsumer(00:00:00.0126036)
[05:26:22 INF] Received Text: Test Name
[05:26:22 DBG] RECEIVE sb://test.servicebus.windows.net/mytopic c7710000-e64a-00ff-fc4d-08d92e12a27a EventBusMessages.Message EventB
usSubscriber.MessageConsumer(00:00:00.0042202)
同样,我每次都发送相同的消息
谢谢你的回答
Web API 项目不应该有接收端点——它没有配置消费者。因此,该接收端点将跳过每条消息。只有在有消费者时才配置接收端点。
并且您只需在添加消费者后调用 ConfigureEndpoints
。