英文:
How to set the Azure Service Bus topic at publishing time with MassTransit?
问题
我正在尝试在发布时设置主题,因为我需要从消息内容中派生它。
我尝试过在发布上下文中工作,就像这样(在一个IPipe
中):
public Task Send(PublishContext<MyMessageType> context)
{
context.DestinationAddress = CalculateDestinationAddress(context);
return Task.CompletedTask;
}
但没有成功。我还尝试寻找其他覆盖主题的方法/时机,但没有找到任何信息。
有人知道如何完成这个任务吗?
英文:
I'm trying to set the topic at publishing time, because I need to derive it from the message content.
I tried to work on the publishing context, like (in a IPipe
):
public Task Send(PublishContext<MyMessageType> context)
{
context.DestinationAddress = CalculateDestinationAddress(context);
return Task.CompletedTask;
}
But didn't work. Also looked for other ways/points to override the topic but didn't find anything.
Anyone aware of how to accomplish this?
答案1
得分: 0
如果您想要发送到任何给定名称的主题,可以使用_topic_地址语法如下:
var endpoint = await sendEndpointProvider.GetSendEndpoint(new Uri("topic:name"));
await endpoint.Send(message);
sendEndpointProvider
可以通过在消费消息时使用 ConsumeContext
获得,或者通过容器中的 ISendEndpointProvider
接口获得。
英文:
If you want to send to a topic of any given name, using the topic address syntax instead:
var endpoint = await sendEndpointProvider.GetSendEndpoint(new Uri("topic:name"));
await endpoint.Send(message);
sendEndpointProvider
is available via the ConsumeContext
when consuming a message, or via the ISendEndpointProvider
interface from the container.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论