Not creating queues automatically in NServiceBus
Asked Answered
H

2

14

I'm running NServiceBus 3.0.0 rc2 but when I start the application (as local admin) without pre-creating the MSMQ's it errors with :

The queue does not exist or you do not have sufficient permissions to perform the operation.

This was not happening using NServiceBus 2.6.

Below is my config:

var bus = Configure.With()
    .Log4Net()
    .NinjectBuilder()
    .XmlSerializer()
    .DefiningCommandsAs(t => typeof(ICommand).IsAssignableFrom(t))
    .DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t))
    .DefiningMessagesAs(t => typeof(IMessage).IsAssignableFrom(t))
    .MsmqTransport()
        .DefineEndpointName("subscriber.input")
        .IsTransactional(true)
        .PurgeOnStartup(false)
    .UnicastBus()
        .LoadMessageHandlers() 
        .ImpersonateSender(false)
    .CreateBus()
    .Start();

and

<configuration>
  <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
  </configSections>    
  <MsmqTransportConfig ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />    
  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="MyEvents" Endpoint="publisher.input" />
    </MessageEndpointMappings>
  </UnicastBusConfig>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

I can see a config extension method to disable automatic creation of queues but none for enabling it.

If I pre-create the queues it works fine.

Hefter answered 1/2, 2012 at 23:41 Comment(1)
Suffering from the same issue this AM...Eardrum
P
15

Installers are not run automatically when you self host. Please see the global.asax.cs in the asyncpages sample for a example on how to do it manually.

using NServiceBus
using NServiceBus.Installation.Environments
...
Bus = Configure.With()
    .Log4Net()
    .DefaultBuilder()
    .XmlSerializer()
    .MsmqTransport()
    .IsTransactional(false)
    .PurgeOnStartup(false)
    .UnicastBus()
    .ImpersonateSender(false)
    .CreateBus()
    .Start(() => Configure.Instance.ForInstallationOn<Windows>().Install());
Preconcert answered 2/2, 2012 at 18:41 Comment(1)
I noticed that this does not create the TimeOut queue. Will it create it when it needs it?Pareto
E
11

I got around this by creating the queue on the client side manually (which is self hosted).

Not sure, but I thought 2.x did this automatically. Host is creating the queues automatically, as expected, but not the client (self hosted).

UPDATE: Like Andreas, senor guardo camino, stated, you need to call install manually like so;

.Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>().Install());

This will create the queues as expected.

Eardrum answered 2/2, 2012 at 18:54 Comment(1)
Is this still so with version 5.2.6 and NServiceBus host 6.0.0? I'm getting: ERROR NServiceBus.Transports.Msmq.MsmqQueueCreator Could not create queue error@...Would

© 2022 - 2024 — McMap. All rights reserved.