- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
正如[在我关于 SO 的一个问题] ( Why a simple configuration in MassTransit creates 2 queues and 3 exchanges? ) 中指出的那样,MassTransit for RabbitMQ 会自动创建一定数量的队列并交换给定的简单配置:
Exchanges, all fanouts:
ConsoleApp1:Program-YourMessage
: DurableVP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt
: Auto-delete and Durable?test_queue
: DurableQueues:
VP0003748_dotnet_bus_6n9oyyfzxhyx9ybobdmpj8qeyt
: x-expire 60000test_queue
: Durable
test_queue
因为这是我决定的足够公平的事情。
最佳答案
这是一个简单而有效的方法:https://bartwullems.blogspot.com/2018/09/masstransitchange-exchange-naming.html
但最好在此处删除一些 dotnet 核心代码,以帮助任何刚开始的人。
我们基于配置的自定义格式化程序:
public class BusEnvironmentNameFormatter : IEntityNameFormatter
{
private readonly IEntityNameFormatter _original;
private readonly string _prefix;
public BusEnvironmentNameFormatter(IEntityNameFormatter original, SomeAppSettingsSection busSettings)
{
_original = original;
_prefix = string.IsNullOrWhiteSpace(busSettings.Environment)
? string.Empty // no prefix
: $"{busSettings.Environment}:"; // custom prefix
}
// Used to rename the exchanges
public string FormatEntityName<T>()
{
var original = _original.FormatEntityName<T>();
return Format(original);
}
// Use this one to rename the queue
public string Format(string original)
{
return string.IsNullOrWhiteSpace(_prefix)
? original
: $"{_prefix}{original}";
}
}
然后要使用它,我们会做这样的事情:
var busSettings = busConfigSection.Get<SomeAppSettingsSection>();
var rabbitMqSettings = rabbitMqConfigSection.Get<SomeOtherAppSettingsSection>();
services.AddMassTransit(scConfig =>
{
scConfig.AddConsumers(consumerAssemblies);
scConfig.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(rmqConfig =>
{
rmqConfig.UseExtensionsLogging(provider.GetRequiredService<ILoggerFactory>());
// Force serialization of default values: null, false, etc
rmqConfig.ConfigureJsonSerializer(jsonSettings =>
{
jsonSettings.DefaultValueHandling = DefaultValueHandling.Include;
return jsonSettings;
});
var nameFormatter = new BusEnvironmentNameFormatter(rmqConfig.MessageTopology.EntityNameFormatter, busSettings);
var host = rmqConfig.Host(new Uri(rabbitMqSettings.ConnectionString), hostConfig =>
{
hostConfig.Username(rabbitMqSettings.Username);
hostConfig.Password(rabbitMqSettings.Password);
});
// Endpoint with custom naming
rmqConfig.ReceiveEndpoint(host, nameFormatter.Format(busSettings.Endpoint), epConfig =>
{
epConfig.PrefetchCount = busSettings.MessagePrefetchCount;
epConfig.UseMessageRetry(x => x.Interval(busSettings.MessageRetryCount, busSettings.MessageRetryInterval));
epConfig.UseInMemoryOutbox();
//TODO: Bind messages to this queue/endpoint
epConfig.MapMessagesToConsumers(provider, busSettings);
});
// Custom naming for exchanges
rmqConfig.MessageTopology.SetEntityNameFormatter(nameFormatter);
}));
});
关于c# - 如何覆盖 MassTransit 默认交换和队列拓扑约定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56074676/
我正在尝试设置 MassTransit 请求/响应场景。问题是消息永远不会到达消费者。我在 PublishRequest 上收到“超时等待响应”错误。日志文件中没有显示其他错误。正在 msmq 中创建
我在传奇中有一些状态并尝试实现状态检查重试,直到我在收到的消息中获得一些令人满意的值。 说,我有这样的事情: .During(Pending, When(StatusChecked)
我在为派生类型发布通用消息以及使用 MassTransit v2.8.0 调用处理程序时遇到问题。 如果我发布类型为 HtmlBlockNewMessage 的消息,永远不会调用消费者。如果我发布 S
我正在尝试在一个微服务中发布消息并在另一个微服务中获取它,但无法使用带有RabbitMQMassTransit 5.5.3 来实现此目的强>. 据我所知,我们不必创建 ReceiveEndpoint
我们对需要保存到某个审计日志数据库的一组事件使用空标记接口(interface)。 但是,在消费者中,消息被强制转换到这个接口(interface),所以我们得到一个空对象。 我们真正需要的是获取“动
我有一个 MassTransit 示例程序,它发布 1 条正文为当前时间戳的消息。然而,奇怪的是,消费者总是有 5 次被调用。 程序如下: public class MassTransitTest {
究竟什么是消费者传奇,它与 Automatonymous 有何不同?我知道 Automatonymous 是 MassTransit 使用的独立库。 最佳答案 Consumer sagas,因为没有更
我正在尝试了解 MassTransit 和 RabbitMQ 并排队(第 1 天) 我的问题是“为了在 MT 中排队工作,是否需要消费者。我问的原因是因为我首先创建了域和生产者,但我没有在 Rabbi
我正在尝试理解 topology of queues并交换 MT 在 RabbitMQ 中创建的。 我不能得到这两个陈述: we generate an exchange for each queue
有谁知道两个应用程序是否可以使用二进制序列化程序通过 MassTransit.RuntimeServices 相互通信? 一旦我将总线配置为使用二进制串行器,应用程序就会在调用 UseSubscrip
我正在尝试结合 Azure 服务总线了解 MassTransit 配置。 在配置时,有 2 个方法具有重载:SubscriptionEndpoint和 RecieveEndpoint .我如何理解使用
我已经开始研究 MassTransit 并正在编写将处理消息的类。当我从 Consumes 实现接口(interface)时我有四个选项:All , Selected , For和 Context .
我有一个 MassTransitStateMachine 来编排一个涉及创建多个事件的过程。 完成所有事件后,我希望状态转换到“清理”阶段。 下面是相关的状态声明和过滤函数: Duri
我有一个特定的标题,我想将它附加到我发布的所有消息中。我可以通过在 Publish 中指定它来逐个附加此 header 。称呼: _bus.Publish(myMessage, context =>
我正在努力了解消息总线和 ioc,但我的脑袋里充满了问题。 这是我的设想 三台电脑通过局域网连接,无法上网。这三台计算机各有一个运行并自动 self 发现其他计算机的服务,换句话说,它们各自在公共(p
我正在为每个消费者实例寻找一种方法来接收通过 MassTransit 发布到 RabbitMQ 的消息。场景是,我们有多个微服务需要在通知时使缓存无效。 Pub-Sub 在这种情况下不起作用,因为每个
我在 fork/join 配置中有一个传奇设置。 在 saga 上定义的事件 FileMetadataMsg FileReadyMsg SomeOtherMsg 当文件进入单独的监听器时,进程开始。
我在下面看到了一个问题及其答案; https://stackoverflow.com/a/46128844/7419921 虽然我知道我不能通过 MassTransit 对错误队列做任何事情,但我应该
什么是状态机 状态机作为一种程序开发范例,在实际的应用开发中有很多的应用场景,其中.NET 中的async/await 的核心底层实现就是基于状态机机制。状态机分为两种:有限状态机和无限状态机,
当您发布消息而不是发送消息时,我在理解 MassTransit 和 Azure 发生的情况时遇到了一个小问题。 基本上我有一个 DownloadWebpage 操作和一个 WebPageDownloa
我是一名优秀的程序员,十分优秀!