matiii
matiii

Reputation: 326

NserviceBus 6.x message pipeline scenario based on transport transaction level

I was reading documentation few times and still its not clear for me how message pipeline looks like when error occur based on transaction level.

enter image description here

Diagram above present pipeline with three handlers which first send command to second and third one subscribe event from second one. When handler 2 processed business logic and start publish event error occur. What will happen based on transport transaction level ? My assumptions are listed below.

  1. Transaction scope level
    Bus rollback transaction. All process start with handler 1 based on recoverability plan (immediate retries and delayed retries). If recoverability plan finish with failure rollback happens and message is moved to error queue. Message can by retried from e.g. service pulse which start pipeline from handler 1 with steps describe earlier.
  2. Transport transaction - Sends atomic with Receive
    Process start from handler 2 based on recoverability plan. If recoverability plan finish with failure message is moved to error queue. Message can by retried from e.g. service pulse which start pipeline from handler 2 with steps describe earlier.

Upvotes: 1

Views: 213

Answers (2)

Dennis van der Stelt
Dennis van der Stelt

Reputation: 2178

I'm not really sure what your scenario is. Based on Sean's answer and your additional question, I'll also try to answer it.

A message is usually send to an endpoint. Each endpoint has a single incoming queue. The message is dispatched to one or more handlers. Usually this is only one.

With distributed transactions (Usually MSDTC in Windows) it depends on which resources you are using that should roll back on an error. MSMQ and SQL Server support MSDTC so that should theoretically work. On an error everything will be rolled back, both the received messages, the SQL transactions and the outgoing messages. You will have a clean state.

SMTP doesn't support transactions, so if you send an email and the transaction rolls back, the email will be sent anyway. So if you retry the message, the email will be send again.

AtomicSendsWithReceive means the transport only participates in the transaction. This means that receiving and sending messages will roll back on an error. But anything done in SQL Server (or any other resource) will not be rolled back.

This is set-up within every endpoint and applies for every incoming message. Since sending of messages via a queue is completely asynchronous, it doesn't matter if you send messages between different endpoints or send every follow-up message to the same endpoint.

Inside NServiceBus there's a pipeline which processes messages. It verifies which transaction to use, which handler(s) to execute, etc. If you're talking about this, there's no way a handler can 'subscribe' to another handler.

If you're talking about message flow, where one handler sends or publishes a new message, then all what I wrote above applies.

Upvotes: 1

Sean Farmar
Sean Farmar

Reputation: 2283

It very much depends on your transport and having DTC as described in the article. If you are using DTC your assumptions are correct in 1 and 2, so it will work with MSMQ or SQL server transports using DTC.

(By the way, if you feel you can improve the article to make it clearer you can submit a pull request)

HTH

Upvotes: 2

Related Questions