Problem with multiple queues and MSMQ

I am new to using the latest version (1.5.8.0) of hangfire

I am trieing to configure multiple queues using the information provided in

I am starting form an empty database and using hangfire within a web service

I have create multiple MSMQ private queues and made sure they have transaction logging on

This is the code I used to start hangfire

        log.Debug("Before config of msq");
        var store = GlobalConfiguration.Configuration
              .UseSqlServerStorage("HangFire")
              .UseMsmqQueues(MSMQNameTemplate, "instrument", "accounts", "default")
       .UseDashboardMetric(SqlServerStorage.ActiveConnections)
       .UseDashboardMetric(SqlServerStorage.TotalConnections)
       .UseDashboardMetric(DashboardMetrics.FailedCount)
       .UseDashboardMetric(DashboardMetrics.ProcessingCount);
        log.Debug("after config of msq");

        log.Debug("Before start of msq werver");
        var newOptions = new BackgroundJobServerOptions
        {
           Queues = new[] { "default", "instrument", "accounts" }, // Include this line only if you have multiple queues
        };
        app.UseHangfireServer(newOptions);
        log.Debug("after start of msq werver");

If I do not pass the queue names to the UseHangFireServer then only the default queue is created.

I thought the line

.UseMsmqQueues(MSMQNameTemplate, “instrument”, “accounts”, “default”)

would have created the queues.


Also I am seeing the following errors in hangfire the log


System.Messaging.MessageQueueException (0x80004005): The transaction usage is invalid.
at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Receive(TimeSpan timeout, MessageQueueTransaction transaction)
at Hangfire.SqlServer.Msmq.MsmqInternalTransaction.Receive(MessageQueue queue, TimeSpan timeout)
at Hangfire.SqlServer.Msmq.MsmqJobQueue.Dequeue(String[] queues, CancellationToken cancellationToken)
at Hangfire.SqlServer.SqlServerConnection.FetchNextJob(String[] queues, CancellationToken cancellationToken)
at Hangfire.Server.Worker.Execute(BackgroundProcessContext context)
at Hangfire.Server.ServerProcessExtensions.Execute(IServerProcess process, BackgroundProcessContext context)
at Hangfire.Server.AutomaticRetryProcess.Execute(BackgroundProcessContext context)

In an attempt to check this problem
I dropped and recreated my hangfire database
I deleted and recreated my msmq queues

I then re-ran my test app and everything worked successfully

I would like to use this in a production environment but having seen the MSMQ exceptions I am not confident.

Is there anyway to produce more detailed information about the exception I have seen

I am getting very same error:

2017-08-28 12:34:00,200 [Worker #77cb0219] ERROR Hangfire.Server.Worker [(null)] - Error occurred during execution of ‘Worker #77cb0219’ process. Execution will be retried (attempt #9) in 00:01:17 seconds.
System.Messaging.MessageQueueException (0x80004005): The transaction usage is invalid.
at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, CursorHandle cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
at System.Messaging.MessageQueue.Receive(TimeSpan timeout, MessageQueueTransaction transaction)
at Hangfire.SqlServer.Msmq.MsmqInternalTransaction.Receive(MessageQueue queue, TimeSpan timeout)
at Hangfire.SqlServer.Msmq.MsmqJobQueue.Dequeue(String[] queues, CancellationToken cancellationToken)
at Hangfire.SqlServer.SqlServerConnection.FetchNextJob(String[] queues, CancellationToken cancellationToken)
at Hangfire.Server.Worker.Execute(BackgroundProcessContext context)
at Hangfire.Server.AutomaticRetryProcess.Execute(BackgroundProcessContext context)

I found the problem, when creating msmq queue don’t forget to mark it as Transactional