Clarifications around using the Outbox functionality to mimic DTCs

266 views
Skip to first unread message

Lee

unread,
Apr 10, 2016, 5:53:12 PM4/10/16
to Particular Software
I am experimenting with the Outbox functionality and have a few questions where my findings don't fully match the what the developer guide states on the Particular website.  I have been working with both the RabbitMQ and SqlServer transports.

My test code simply sends a message, inserts a row into a SQL table and then throws an exception.  The retry then occurs and doesn't throw an exception.  The behaviour I expect is that only 1 row should be inserted into my SQL table and the message should only be sent once.

On http://docs.particular.net/nservicebus/outbox/ it states the following caveats...
  1. Both the business data and deduplication data need to share the same database.
  2. The Outbox is bypassed when a message is sent outside of an NServiceBus message handler. This is because there is no mechanism for repeated dispatching of the Outbox messages other than the standard retry logic, which won't be triggered in this case.
In regards to 1.), I have my 'business data' and deduplication data in two different databases and I still get the behaviour I expect.  Is my test code incorrect? Or is this caveat inaccurate?

In regards to 2.), what are examples of messages being sent outside of an NServiceBus message handler?

On the same webpage as the link above it also states: -
  1. To keep track of duplicate messages, the NHibernate implementation of Outbox requires the creation of two additional tables in the database: OutboxRecord and OutboxOperation.
In my tests, OutboxRecord has been created but I haven't seen OutboxOperation.  Any ideas why the second table is not being created?  Everything still seems to work as expected.

Finally, are there any distinct advantages of using either the SQL Server or RabbitMQ transport when it comes to the Outbox functionality or do they offer exactly the same guarantees?

Thanks!

Szymon Pobiega

unread,
Apr 11, 2016, 1:03:30 AM4/11/16
to particula...@googlegroups.com
Hi

1. Having business and outbox tables in same DB and being access via same connection is essential if the failure happens after you committed your business data to DB but before the outbox inserts its deduplication data. In such case, after the first processing attempt, you would end up with a row in business data table but no data in outbox store so when retrying the business data will be inserted again. That said, if you test on a myachine with DTC enabled you would not notice that behavior because both connections would automatically enlist in a distributed transaction

2. Sending from outside of a handler happens whenever you use IBus instance returned from Bus.Start. Outbox works only when sending from IBus injected to a message handler while processing an incoming message

3. OutboxOperation in the documentation is a lefover. I've fixed that paragraph. There is only a single table needed: OutboxRecord

4. Outbox works the same way in all transports so in this regard there is no difference between SQL Server and Rabbit MQ. That being said, as stated here http://docs.particular.net/nservicebus/outbox/#using-outbox-with-nhibernate-persistence when using NH and SQL transport you can use the same connection string and achieve exactly-once bahavior by means of sharing a connection.

Hope that helps,
Szymon

--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at https://groups.google.com/group/particularsoftware.
To view this discussion on the web visit https://groups.google.com/d/msgid/particularsoftware/31d608de-c683-4234-a9f7-3bbf8aed2803%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lee

unread,
Apr 11, 2016, 4:19:07 AM4/11/16
to Particular Software
Thanks for the reply!  Have a couple more questions...

1.)  I thought that SQL Server 2008 supported transactions across multiple databases without escalating to DTC?  Can you explain why that doesn't work here?

4.) To clarify, by using outbox you achieve exactly-once behaviour in both RabbitMQ and SQL Server but when using SQL Server you can also achieve exactly-once behaviour with Outbox disabled if you share the connection?  If that is the case why would you ever do one over the other?

Can you elaborate on the following: -
  • From the perspective of a particular endpoint this is exactly-once processing because of the deduplication that happens on the incoming queue. From a global point of view this is at-least-once since on the wire messages can get duplicated.
Thanks again!

Szymon Pobiega

unread,
Apr 11, 2016, 4:55:27 AM4/11/16
to particula...@googlegroups.com
Hi

1. Yes, it does. The current version of NServiceBus does not support catalog-qualified table names so the connection string has to contain the name of the initial catalog. This makes it not possible to use cross-catalog transaction within a single database instance

4. Sharing connection has two advantages:
 - there is less DB access because with outbox messages are first stored in the OutboxRecord and then inserted to queue table. With connection sharing there is no overhead of the OutboxRecord table
 - (related to your next point) with outbox the messages _on_the_wire_ might get duplicated because dispatching them from OutboxRecord to the queue is done in at-least-once manner. If dispatching fails, it is retried even if the failure happened after the queue acknowledged sending the message. The receiver with an outbox will ignore the duplicate because it stores its own OutboxRecord for each incoming message.

Szymon

--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at https://groups.google.com/group/particularsoftware.
Reply all
Reply to author
Forward
0 new messages