我正在尝试在现有的 Windows 服务中自托管 一个分发服务器。 我正在使用 MSMQ Transport,下面是总线的创建方式:
NServiceBus.Configure.With()
.DefaultBuilder()
.EnlistWithDistributor()
.JsonSerializer()
.UseTransport<Msmq>()
.UnicastBus()
.CreateBus()
.Start();
我需要覆盖默认的 Queue 名称(自动从 Assembly 命名空间派生),我试图通过以下方式定义 EndPointConfig,不幸的是,它没有更改 Q 名称。
[NServiceBus.EndpointName("custon.queue.name")]
public class EndpointConfig : NServiceBus.IConfigureThisEndpoint, NServiceBus.AsA_Publisher
{
public EndpointConfig()
{
}
}
配置部分
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core"/>
<section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core"/>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
<section name="TransportConfig" type="NServiceBus.Config.TransportConfig, NServiceBus.Core"/>
</configSections>
<AuditConfig QueueName="audit"/>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>
<TransportConfig MaximumConcurrencyLevel="10" MaxRetries="3" MaximumMessageThroughputPerSecond="10"/>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Protocols" Endpoint="custom.queue.name@localhost"/>
</MessageEndpointMappings>
</UnicastBusConfig>
如何覆盖自托管时使用的队列名称?
任何帮助将不胜感激。
请您参考如下方法:
自托管时,没有 EndpointConfig 类 - 配置完全来自您的流畅配置 block 。您的 EndpointConfig 类被忽略了。
通过流畅的配置,更改端点名称(特别是说“更改输入队列”是用词不当 - 它是从端点名称中删除的)是这样完成的:
Configure.With()
.DefineEndpointName("MyEndpointName")
// Rest of config
或者如果您希望能够从数据库或配置文件中提取它或做一些花哨的事情...
Configure.With()
.DefineEndpointName(() =>
{
// determine and return endpoint name
})
// Rest of config
端点名称对配置中的其他所有内容都至关重要,因此它应该是流畅配置链中的第一项。
另见 How to Specify Your Input Queue来自 NServiceBus 文档。
