简体   繁体   中英

Setting NServiceBus Endpoint Name / Input Queue when self-hosting

I am Trying to self-host a Distributor in an existing windows service. I am using MSMQ Transport, The following is how the bus is being created:

NServiceBus.Configure.With()
.DefaultBuilder()
.EnlistWithDistributor()
.JsonSerializer()
.UseTransport<Msmq>()
.UnicastBus()
.CreateBus()
.Start();

I need to override the default Queue name ( automatically derived from the Assembly namespace ), I was trying to define an EndPointConfig in the following way, Unfortunetly, it didn't made the Q name change.

[NServiceBus.EndpointName("custon.queue.name")]
public class EndpointConfig : NServiceBus.IConfigureThisEndpoint, NServiceBus.AsA_Publisher 
{
    public EndpointConfig()
    {
    }
}

Config section


  <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>



How can I override the name of the Queue used when self-hosting ?
Any help will be appreciated.

When self-hosting, there is no EndpointConfig class - the configuration is completely derived from your fluent config block. Your EndpointConfig class is being ignored.

Through the fluent config, changing the endpoint name (specifically saying "change the input queue" is a misnomer - it is driven off the endpoint name) is done like this:

Configure.With()
    .DefineEndpointName("MyEndpointName")
    // Rest of config

or if you want to be able to pull it from a database or config file or do something fancy...

Configure.With()
    .DefineEndpointName(() =>
        {
            // determine and return endpoint name
        })
    // Rest of config

The endpoint name is critical to everything else in the config, so it should be the very first item in the fluent config chain.

Also see How to Specify Your Input Queue from the NServiceBus documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM