英文:
MassTransit - Register Consumer to multiple endpoints
问题
public class Message
{
public object Payload { get; set; }
}
public class Consumer1 : IConsumer<Message>
{
//... handler code
}
public class Consumer2 : IConsumer<Message>
{
//... handler code
}
我想将Consumer1
注册到endpoint_1、endpoint_2和endpoint_3,而Consumer2
注册到endpoint_1和endpoint_2。
英文:
In MassTransit
how can a Consumer
register to multiple endpoints?
public class Message
{
public object Payload { get; set; }
}
public class Consumer1 : IConsumer<Message>
{
//... handler code
}
public class Consumer2 : IConsumer<Message>
{
//... handler code
}
And I'd like to register Consumer1
to endpoint_1, endpoint_2 and endpoint_3, while Consumer2
is registered to endpoint_1 and endpoint_2
答案1
得分: 1
你需要手动配置这些接收端点以及它们上面的消费者,按照文档中的指导进行操作。
services.AddMassTransit(x =>
{
x.AddConsumer<Consumer1>();
x.AddConsumer<Consumer2>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.ReceiveEndpoint("endpoint_1", e =>
{
e.ConfigureConsumer<Consumer1>(context);
e.ConfigureConsumer<Consumer2>(context);
});
cfg.ReceiveEndpoint("endpoint_2", e =>
{
e.ConfigureConsumer<Consumer1>(context);
e.ConfigureConsumer<Consumer2>(context);
});
cfg.ReceiveEndpoint("endpoint_3", e =>
{
e.ConfigureConsumer<Consumer1>(context);
});
});
});
英文:
You'd need to manually configure those receive endpoints, and the consumer(s) on each of them, following the guidance in the documentation.
services.AddMassTransit(x =>
{
x.AddConsumer<Consumer1>();
x.AddConsumer<Consumer2>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.ReceiveEndpoint("endpoint_1", e =>
{
e.ConfigureConsumer<Consumer1>(context);
e.ConfigureConsumer<Consumer2>(context);
});
cfg.ReceiveEndpoint("endpoint_2", e =>
{
e.ConfigureConsumer<Consumer1>(context);
e.ConfigureConsumer<Consumer2>(context);
});
cfg.ReceiveEndpoint("endpoint_3", e =>
{
e.ConfigureConsumer<Consumer1>(context);
});
});
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论