Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.78 KB

transactions_in_exchange_modules.md

File metadata and controls

42 lines (30 loc) · 1.78 KB

What are those transactions inside the exchange callback modules?

Many callbacks inside the rabbit_exchange_type behaviour expect a tx() parameter which is defined as follows:

-type(tx() :: 'transaction' | 'none').

Then for example create is defined like:

 %% called after declaration and recovery
-callback create(tx(), rabbit_types:exchange()) -> 'ok'.

The question is, what's the purpose of that transaction parameter?

This is related to how RabbitMQ runs Mnesia transactions for its internal bookkeeping:

rabbit_misc:execute_mnesia_transaction/2

As you can see in that code there's this PrePostCommitFun which is called in Mnesia transaction context, and after the transaction has run.

So here for example: in rabbit_exchange:declare/7 the create callback from the exchange is called inside a Mnesia transaction, and outside of afterwards.

You can see this in action/understand the usefulness of it when considering an exchange like the topic exchange which keeps track of its own data structures:

rabbit_exchange_type_topic:delete/3 rabbit_exchange_type_topic:add_binding/3 rabbit_exchange_type_topic:remove_bindings/3

Deleting the exchange, adding or removing bindings, are all done inside a Mnesia transaction for consistency reasons.