JBoss.org Community Documentation

- Prev
- Next

## Chapter 45. Intercepting Operations

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.

## 45.1. Implementing The Interceptors

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.

## 45.2. Configuring The Interceptors

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.

## 45.3. Interceptors on the Client Side

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.

## 45.4. Example

See Section 11.1.25, “Interceptor” for an example which shows how to use interceptors to add properties to a message on the server.

- PrevChapter 44. Spring Integration
- Top of page
- Front page
- NextChapter 46. Interoperability