使用公共交通。一切工作正常,并且消费/发布到预先创建的正确主题/队列。
但它正在创建它不使用的额外主题/订阅。我尝试跟踪并拼凑不同的可用选项,但 MT 要么没有发布到正确的主题,要么没有效果。
设置代码:
services.AddMassTransit((cfg) =>
{
cfg.AddConsumer<WorkOneConsumer, WorkOneConsumerDefinition>()
.Endpoint(e =>
{
e.Name = "queue:" + MassTransitDemoConstants.WORKFLOWONE_QUEUE;
e.Temporary = true;
e.ConfigureConsumeTopology = false;
});
cfg.AddConsumer<WorkTwoConsumer, WorkTwoConsumerDefinition>()
.Endpoint(e =>
{
e.Name = "queue:" + MassTransitDemoConstants.WORKFLOWTWO_QUEUE;
e.Temporary = true;
e.ConfigureConsumeTopology = false;
});
cfg.UsingAzureServiceBus((context, config) =>
{
config.Host(Configuration.GetValue<string>("AppSettings:ServiceBusConnectionString"));
//config.UseRateLimit();
//config.UseMessageRetry();
//config.UseCircuitBreaker();
config.Message<IWorkflowOneCompletedEvent>(config => config.SetEntityName(MassTransitDemoConstants.WORKFLOW_TOPIC));
config.Message<IWorkflowTwoCompletedEvent>(config => config.SetEntityName(MassTransitDemoConstants.WORKFLOW_TOPIC));
config.Message<IWorkflowFailedEvent>(config => config.SetEntityName(MassTransitDemoConstants.WORKFLOW_TOPIC));
config.ReceiveEndpoint(MassTransitDemoConstants.WORKFLOWONE_QUEUE, e =>
{
e.ConfigureConsumeTopology = false;
e.Consumer<WorkOneConsumer>(context);
});
config.ReceiveEndpoint(MassTransitDemoConstants.WORKFLOWTWO_QUEUE, e =>
{
e.ConfigureConsumeTopology = false;
e.Consumer<WorkTwoConsumer>(context);
});
config.Publish<IWorkflowOneCompletedEvent>(x => x.Exclude = true);
config.DeployPublishTopology = false;
config.ConfigureEndpoints(context);
});
});
这是工作人员功能之一。它尝试监听 WorkOne / WorkTwo 命令(通过工作完美的队列),并将事件(通过主题)发布到主题“test”,即“MassTransitDemoConstants.WORKFLOW_TOPIC”的值。
它不是在启动时创建这些主题 - 当我在消费者上发布该事件时,它会创建这些额外的主题:
await _publishEndpoint.Publish(new WorkflowOneCompletedEvent
{
CorrelationId = command.CorrelationId,
SubscriptionName = MassTransitDemoConstants.WORKFLOW_ONECOMPLETE_SUBSCRIPTION,
ConsumerDataName = "WorkerProject.Function"
}, context => { context.Headers.Set("subscriptionName", MassTransitDemoConstants.WORKFLOW_ONECOMPLETE_SUBSCRIPTION); });
上面的这一行将
workerproject.function.models~workflowonecompletedevent
创建为主题,并将 MassTransitDemoConstants.WORKFLOW_TOPIC (which is 'test')
创建为该主题的订阅。 至少应该是相反的。
对我当前的设置没有任何作用。
重申一下,这些程序正在运行 - 我能够看到我的传奇成功完成。我只是看到这些额外的主题和订阅。
理想的场景是 MT 不自行创建任何主题/订阅。为此,我尝试设置
ConfigureConsumeTopology = false
,DeployPublishTopology = false
,一些属性:
[ConfigureConsumeTopology...]
[ExcludeFromTopology]
[ExcludeFromImplementedTypes]
但无济于事。
我的设置有什么问题吗?
e.Consumer<WorkOneConsumer>(context);
应该是
e.ConfigureConsumer<WorkOneConsumer>(context);
这个:
.Endpoint(e => { e.Name = "queue:" + MassTransitDemoConstants.WORKFLOWONE_QUEUE; e.Temporary = true; e.ConfigureConsumeTopology = false; })
毫无意义,因为您正在手动配置接收端点。您还可以删除:
config.ConfigureEndpoints(context);