JBoss.orgCommunity Documentation

Chapter 45. Intercepting Operations

45.1. Implementing The Interceptors
45.2. Configuring The Interceptors
45.3. Interceptors on the Client Side
45.4. Example

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:

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.