Skip to content

TransactionalRouter

busterwood edited this page Jan 3, 2018 · 1 revision

Create a TransactionalRouter to read an input transactional queue and send messages onto destination queues.

Properties:

  • MaxBatchSize the maximum number of messages to process per transaction, defaults to 250.
  • InProgressSubQueue the subqueue to use to handle error recovery, defaults to batch
  • PeekProperties the properties used when peeking for messages
  • UnroutableSubQueue the subqueue to move messages to on error or if the router function returns null.
  • BadMessageHandler used to override change the behaviour of handling messages that cannot be routed.

Methods:

  • StartAsync() starts the router
  • StopAsync() stops the router
  • Dipose() also stops the router

The TransactionalRouter constructor takes an router argument of type Func<Message, QueueWriter> that is used to determine where to move the message to.

Note that you may like to use a QueueCache when routing messages to large numbers of destination queues.

Routing a message to multiple destinations

To route messages to multiple destination queues the router function should return a QueueWriter that sends to multiple destinations, e.g. multicast, distribution list or multi-element format name.

Why?

Efficiently routing transactional messages is a bit tricky as each transaction has a fix overhead, so routing one message at a time is quite slow. The way to get reasonable performance is to handling multiple messages in each transaction, but that is more complex, hence this pattern.

The process used by this class is:

0) Recover - wait for acks for each message in batch                           
1) Peek message                                                                
2) begin transaction                                                           
3)    move to "batch" subqueue                                                  
4)    send                                                                      
5) commit                                                                      
6) for each message in batch                                                   
7)   wait for ack
        on success remove message from "batch" subqueue
        on failure message move to UnroutableSubQueue