【问题标题】:How to set RabbitMQ queue prefix when using CAP使用 CAP 时如何设置 RabbitMQ 队列前缀
【发布时间】:2020-02-24 21:00:17
【问题描述】:
我们将 dotnetcore/CAP 与 RabbitMQ 一起使用。我遵循与其他 CAP 代码相同的设置,但由于某种原因,我的队列名称上出现了“cap.queue”前缀。
我们所有的其他队列都是这样命名的:
[NameInAppSettings].v1
由于某种原因,我的新队列是这样的:
cap.queue.[NameInAppSettings].v1
默认组是这样设置的:
services.AddCap(options =>
{
options.DefaultGroup = Configuration["SubscriptionClientName"];
}
我已经确认 appsettings 设置存在并且我们正在访问上面的代码行。在上述行执行之前,options.DefaultGroup 具有“cap.queue”前缀。该行执行后,它只是“[NameInAppSettings].v1”。那么为什么队列名称在 RMQ 仪表板中查看时具有“cap.queue”前缀?我在哪里可以设置?
【问题讨论】:
标签:
c#
.net-core
rabbitmq
【解决方案1】:
似乎有两个设置可以控制此行为。
首先,DefaultGroup 确实需要设置。
其次,ExchangeName也需要设置。
这些值只需要存在即可。如果缺少它们,则将创建默认交换/队列。
这两个都显示在这里:
services.AddCap(x =>
{
// other settings here
x.DefaultGroup = "Sandbox";
x.UseRabbitMQ(conf =>
{
conf.ExchangeName = "SandboxEventBus";
conf.ConnectionFactoryOptions = x =>
{
x.Uri = BuildRabbitUri();
};
});
});
为了完整起见,这里是BuildRabbitUri():
public static Uri BuildRabbitUri()
{
string protocol = "amqp";
string userName = "guest";
string password = "guest";
string host = "localhost";
string port = "6003";
return new Uri(protocol + "://" + userName + ":" + password + "@" + host + ":" + port);
}