<commit_before># Intercepting Operations

Apache ActiveMQ Artemis supports *interceptors* to intercept packets entering
and exiting the server. Incoming and outgoing interceptors are be called for
any packet entering or exiting the server respectively. This allows custom code
to be executed, e.g. for auditing packets, filtering or other reasons.
Interceptors can change the packets they intercept. This makes interceptors
powerful, but also potentially dangerous.

## Implementing The Interceptors

All interceptors are protocol specific.

An interceptor for the core protocol must implement the interface
`Interceptor`:

```java
package org.apache.activemq.artemis.api.core.interceptor;

public interface Interceptor
{
   boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException;
}
```

For stomp protocol an interceptor must implement the interface `StompFrameInterceptor`:

```java
package org.apache.activemq.artemis.core.protocol.stomp;

public interface StompFrameInterceptor extends BaseInterceptor<StompFrame>
{
   boolean intercept(StompFrame stompFrame, RemotingConnection connection);
}
```

Likewise for MQTT protocol, an interceptor must implement the interface
`MQTTInterceptor`:
 
```java package org.apache.activemq.artemis.core.protocol.mqtt;

public interface MQTTInterceptor extends BaseInterceptor<MqttMessage>
{
    boolean intercept(MqttMessage mqttMessage, RemotingConnection connection);
}
```

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 processed further by the server.<commit_msg>NO-JIRA Fixing markdown format in intercepting-operations.md<commit_after># Intercepting Operations

Apache ActiveMQ Artemis supports *interceptors* to intercept packets entering
and exiting the server. Incoming and outgoing interceptors are be called for
any packet entering or exiting the server respectively. This allows custom code
to be executed, e.g. for auditing packets, filtering or other reasons.
Interceptors can change the packets they intercept. This makes interceptors
powerful, but also potentially dangerous.

## Implementing The Interceptors

All interceptors are protocol specific.

An interceptor for the core protocol must implement the interface
`Interceptor`:

```java
package org.apache.activemq.artemis.api.core.interceptor;

public interface Interceptor
{
   boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException;
}
```

For stomp protocol an interceptor must implement the interface `StompFrameInterceptor`:

```java
package org.apache.activemq.artemis.core.protocol.stomp;

public interface StompFrameInterceptor extends BaseInterceptor<StompFrame>
{
   boolean intercept(StompFrame stompFrame, RemotingConnection connection);
}
```

Likewise for MQTT protocol, an interceptor must implement the interface
`MQTTInterceptor`:
 
```java
package org.apache.activemq.artemis.core.protocol.mqtt;

public interface MQTTInterceptor extends BaseInterceptor<MqttMessage>
{
    boolean intercept(MqttMessage mqttMessage, RemotingConnection connection);
}
```

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 processed further by the server.
{'fraction_non_alphanumeric': 0.059060789397868046, 'fraction_numerical': 0.0, 'mean_word_length': 5.875247524752475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4660994', 'n_tokens_mistral': 932, 'n_tokens_neox': 866, 'n_words': 364}