Chapter 11. Intercepting messages
Interceptors give you the ability to intercept packets as they enter or exit the broker, which allows you to audit packets or filter messages. Interceptors can change the packets they intercept, which makes them powerful, but also potentially dangerous.
You can develop interceptors to meet your business requirements. Interceptors are protocol specific and must implement the appropriate interface.
Interceptors must implement the intercept() method, which returns a boolean value. If the value is true, the message packet continues onward. If false, the process is aborted, no other interceptors are called, and the message packet is not processed further.
11.1. Creating interceptors Copy linkLink copied to clipboard!
You can create custom incoming and outgoing interceptors to meet organizational requirements such as auditing packets. All interceptors are protocol specific and are called for any packet entering or exiting the server.
Interceptors can change the packets they intercept. This makes them powerful and potentially dangerous, so be sure to use them with caution.
You must place interceptors and their dependencies in the Java classpath of the broker. You can use the <broker_instance_dir>/lib directory since it is part of the classpath by default.
The following example shows how to create an interceptor that checks the size of each packet passed to it.
Procedure
Implement the appropriate interface and override its
intercept()method.If you are using the AMQP protocol, implement the
org.apache.activemq.artemis.protocol.amqp.broker.AmqpInterceptorinterface.Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using Core Protocol, your interceptor must implement the
org.apache.artemis.activemq.api.core.Interceptorinterface.Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using the MQTT protocol, implement the
org.apache.activemq.artemis.core.protocol.mqtt.MQTTInterceptorinterface.Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are using the STOMP protocol, implement the
org.apache.activemq.artemis.core.protocol.stomp.StompFrameInterceptorinterface.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.2. Configuring the broker to use interceptors Copy linkLink copied to clipboard!
After you create an interceptor, you must configure the broker to activate the interceptor so it can intercept packets as they enter or exit the broker.
Prerequisites
You must create an interceptor class and add it (and its dependencies) to the Java classpath of the broker before you can configure it for use by the broker. You can use the <broker_instance_dir>/lib directory since it is part of the classpath by default.
Procedure
Configure the broker to use an interceptor by adding configuration to
<broker_instance_dir>/etc/broker.xml.If your interceptor is intended for incoming messages, add its
class-nameto the list ofremoting-incoming-interceptors.Copy to Clipboard Copied! Toggle word wrap Toggle overflow If your interceptor is intended for outgoing messages, add its
class-nameto the list ofremoting-outgoing-interceptors.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources