Used Version of NServiceBus: 2.0.0.1145
Question:
Is it possible to configure a NServiceBus in such way that, it consumes (subcribes to) his own published messages?
Answer:
It seems possible, but in the following Configuration it gives me a Transaction deadlocked Exception while trying to insert Subscriptions into the SubscriptionStorage. It happens when you use DbSubscriptionStorage and more than 1 "NumberOfWorkerThreads".
Error:
Could not execute command:
INSERT INTO Subscription (SubscriberEndpoint, MessageType) VALUES (@p0, @p1)
System.Data.SqlClinet.SqlException:
Transaction was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
After that NServiceBus tries to disconnect but fails because there is a transaction still in progress and throws an UnhandledException.
How to reproduce:
Here is my App.Config:
<!-- Publishing Configuration -->
<MsmqTransportConfig InputQueue="test_publisher_output" ErrorQueue="test_error" NumberOfWorkerThreads="3" MaxRetries="5" />
<!-- Subscription Configuration -->
<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
<add Messages="MessageAssembly" Endpoint="test_publisher_output" />
</MessageEndpointMappings>
</UnicastBusConfig>
My Bus-Configuration:
var bus = Configure.With()
.Log4Net()
.StructureMapBuilder(container)
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.DBSubcriptionStorage(subscriptionDbProperties, true)
.Sagas()
.NHibernateSagaPersister(sagaDbProperties, true)
.UnicastBus()
.ImpersonateSender(false)
.LoadMessageHandlers(First<GridInterceptingMessageHandler>
.Then<SagaMessageHandler>())
.CreateBus()
.Start();
and here are my dbProperties for both the subscription and the saga db:
connection.provider NHibernate.Connection.DriverConnectionProvider
connection.driver_class NHibernate.Driver.SqlClientDriver
dialect NHibernate.Dialect.MsSql2005Dialect
Everything works fine as long as i don't increase the NumberOfWorkerThreads above 1. But above that i get the above stated errors.
I hope i haven't forgotten anything. Thanks for your help in advance.