如何解决大众运输和Azure服务总线:消息被不同的开发人员空间多次使用
我以这种方式注册后发布了一条消息(评论行已完成许多尝试)。 我传递了queuePrefix以便使用不同的开发空间,每个开发人员一个,因为该应用程序基于微服务。 大众运输将不同微服务之间的信息交换解耦
this IServiceBusBusFactoryConfigurator cfg,IServiceProvider provider,string queuePrefix = null,Action<IConsumerConfigurator<TConsumer>> configure = null)
where TConsumer : class,IConsumer<TCommand>
where TCommand : class
{
string queueName = $"{queuePrefix}-{typeof(TCommand).Name}";
cfg.Message<TCommand>(configureTopology => {
//configureTopology.SetEntityName(queueName);
//configureTopology.UsePartitionKeyFormatter(context => context.Message.CustomerId);
});
cfg.Publish<TCommand>(configureTopology => {
configureTopology.EnablePartitioning = true;
//configureTopology.UsePartitionKeyFormatter(context => context.Message.CustomerId);
});
cfg.Send<TCommand>(x =>
{
//x.UsePartitionKeyFormatter(context => context..Message.CustomerId);
});
cfg.ReceiveEndpoint(queueName,endpointCfg =>
{
endpointCfg.RemoveSubscriptions = true;
endpointCfg.EnablePartitioning = true;
endpointCfg.Consumer<TConsumer>(provider,configure);
});
return cfg;
}
我虽然前缀就足够了,但是如果我发布一条消息,则所有开发人员空间都会消耗该消息。 我该怎么办?我尝试订阅失败。看来我走错了路
解决方法
原因是每种消息类型具有相同的主题名称,并且所有开发空间都订阅相同的主题。您可以通过创建自己的IEntityNameFormatter
来覆盖主题名称,类似于覆盖队列名称以包含前缀的方式,类似于在this question/answer中进行的操作。
MassTransit包含一个实体名称格式器PrefixEntityNameFormatter
,它是在v7中添加的,其作用相同,您只需在总线配置上为消息拓扑指定它即可。
cfg.MessageTopology.SetEntityNameFormatter(
new PrefixEntityNameFormatter(cfg.MessageTopology.EntityNameFormatter,"Frank-"));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。