You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 7, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: part-iii-infrastructure-components/command-dispatching.md
+57
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,33 @@ There are different types of interceptors: Dispatch Interceptors and Handler Int
158
158
159
159
Message Dispatch Interceptors are invoked when a command is dispatched on a Command Bus. They have the ability to alter the Command Message, by adding Meta Data, for example, or block the command by throwing an Exception. These interceptors are always invoked on the thread that dispatches the Command.
160
160
161
+
Let's create a Message Dispatch Interceptor which logs each command message being dispatched on a `CommandBus`.
There is no point in processing a command if it does not contain all required information in the correct format. In fact, a command that lacks information should be blocked as early as possible, preferably even before any transaction is started. Therefore, an interceptor should check all incoming commands for the availability of such information. This is called structural validation.
@@ -180,6 +207,36 @@ Unlike Dispatch Interceptors, Handler Interceptors are invoked in the context of
180
207
181
208
Handler Interceptors are also typically used to manage transactions around the handling of a command. To do so, register a `TransactionManagingInterceptor`, which in turn is configured with a `TransactionManager` to start and commit \(or roll back\) the actual transaction.
182
209
210
+
Let's create a Message Handler Interceptor which will only allow the handling of commands that contain `axonUser` as a value for the `userId` field in the `MetaData`. If the `userId` is not present in the meta-data, an exception will be thrown which will prevent the command from being handled. And if the `userId`'s value does not match `axonUser`, we will also not proceed up the chain.
TheCommandBus implementations described in earlier only allow CommandMessages to be dispatched within a single JVM. Sometimes, you want multiple instances of CommandBuses in different JVMs to act as one. Commands dispatched on one JVM's Command Bus should be seamlessly transported to a Command Handler in another JVM while sending back any results.
0 commit comments