JBoss.orgCommunity Documentation
HornetQ supports interceptors to intercept packets entering the server. Any supplied interceptors would be called for any packet entering the server, this allows custom code to be executed, e.g. for auditing packets, filtering or other reasons. Interceptors can change the packets they intercept.
A interceptor must implement the Interceptor interface
:
package org.hornetq.api.core.interceptor; public interface Interceptor { boolean intercept(Packet packet, RemotingConnection connection) throws HornetQException; }
The returned boolean value is important:
if true
is returned, the process continues normally
if false
is returned, the process is aborted, no other
interceptors will be called and the packet will not be handled by the server at
all.
The interceptors are configured in hornetq-configuration.xml
:
<remoting-interceptors> <class-name>org.hornetq.jms.example.LoginInterceptor</class-name> <class-name>org.hornetq.jms.example.AdditionalPropertyInterceptor</class-name> </remoting-interceptors>
The interceptors classes (and their dependencies) must be added to the server classpath to be properly instantiated and called.
The interceptors can also be run on the client side to intercept packets
sent by the server by adding the interceptor to the ClientSessionFactory
with the addInterceptor()
method.
The interceptors classes (and their dependencies) must be added to the client classpath to be properly instantiated and called from the client side.
See Section 11.1.26, “Interceptor” for an example which shows how to use interceptors to add properties to a message on the server.