Skip to content

Commit

Permalink
This closes #2871
Browse files Browse the repository at this point in the history
  • Loading branch information
clebertsuconic committed Nov 6, 2019
2 parents f61d12c + c9f5608 commit 111b9cc
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/user-manual/en/SUMMARY.md
Expand Up @@ -56,6 +56,7 @@
* [Client Reconnection and Session Reattachment](client-reconnection.md)
* [Diverting and Splitting Message Flows](diverts.md)
* [Core Bridges](core-bridges.md)
* [Transformers](transformers.md)
* [Duplicate Message Detection](duplicate-detection.md)
* [Clusters](clusters.md)
* [Federation](federation.md)
Expand Down
11 changes: 4 additions & 7 deletions docs/user-manual/en/core-bridges.md
Expand Up @@ -93,13 +93,10 @@ Let's take a look at all the parameters in turn:
string will be forwarded. The filter string follows the ActiveMQ Artemis filter
expression syntax described in [Filter Expressions](filter-expressions.md).

- `transformer-class-name`. An optional transformer-class-name can be
specified. This is the name of a user-defined class which implements the
`org.apache.activemq.artemis.core.server.transformer.Transformer` interface.

If this is specified then the transformer's `transform()` method will be
invoked with the message before it is forwarded. This gives you the opportunity
to transform the message's header or body before forwarding it.
- `transformer-class-name`. An *optional* transformer can be specified. This
gives you the opportunity to transform the message's header or body before
forwarding it. See the [transformer chapter](transformers.md) for more details
about transformer-specific configuration.

- `ha`. This optional parameter determines whether or not this bridge should
support high availability. True means it will connect to any available server
Expand Down
28 changes: 15 additions & 13 deletions docs/user-manual/en/diverts.md
Expand Up @@ -31,12 +31,12 @@ vice-versa. By configuring the `routing-type` of the divert you have the
flexibility to deal with any situation. Valid values are `ANYCAST`,
`MULTICAST`, `PASS`, & `STRIP`. The default is `STRIP`.

Diverts can also be configured to apply a `Transformer`. If specified,
all diverted messages will have the opportunity of being transformed by
the `Transformer`. When an address has multiple diverts configured, all
of them receive the same, original message. This means that the results
of a transformer on a message are not directly available for other
diverts or their filters on the same address.
Diverts can also be configured to apply a [`Transformer`](transformers.md).
If specified, all diverted messages will have the opportunity of being
transformed by the `Transformer`. When an address has multiple diverts
configured, all of them receive the same, original message. This means that
the results of a transformer on a message are not directly available for
other diverts or their filters on the same address.

See the documentation on [adding runtime dependencies](using-server.md) to
understand how to make your transformer available to the broker.
Expand Down Expand Up @@ -100,16 +100,18 @@ other messages will continue to be routed to the normal address. The
filter string is optional, if not specified then all messages will be
considered matched.

In this example a transformer class is specified. Again this is
optional, and if specified the transformer will be executed for each
matching message. This allows you to change the messages body or
properties before it is diverted. In this example the transformer simply
adds a header that records the time the divert happened.
In this example a transformer class is specified without any configuration
properties. Again this is optional, and if specified the transformer will
be executed for each matching message. This allows you to change the
messages body or properties before it is diverted. In this example the
transformer simply adds a header that records the time the divert happened.
See the [transformer chapter](transformers.md) for more details about
transformer-specific configuration.

This example is actually diverting messages to a local store and forward
queue, which is configured with a bridge which forwards the message to
an address on another ActiveMQ Artemis server. Please see the example for more
details.
an address on another ActiveMQ Artemis server. Please see the example for
more details.

## Non-exclusive Divert

Expand Down
50 changes: 50 additions & 0 deletions docs/user-manual/en/transformers.md
@@ -0,0 +1,50 @@
# Transformers

A transfomer, as the name suggests, is a component which transforms a message.
For example, a transformer could modify the body of a message or add or remove
properties. Both [diverts](diverts.md) and [core bridges](core-bridges.md)
support.

A transformer is simply a class which implements the interface
`org.apache.activemq.artemis.core.server.transformer.Transformer`:

```java
public interface Transformer {

default void init(Map<String, String> properties) { }

Message transform(Message message);
}
```

The `init` method is called immediately after the broker instantiates the class.
There is a default method implementation so implementing `init` is optional.
However, if the transformer needs any configuration properties it should
implement `init` and the broker will pass the configured key/value pairs to the
transformer using a `java.util.Map`.

## Configuration

The most basic configuration requires only specifying the transformer's class
name, e.g.:

```xml
<transformer-class-name>
org.foo.MyTransformer
</transformer-class-name>
```

However, if the transformer needs any configuration properties those can be
specified using a slightly different syntax, e.g.:

```xml
<transformer>
<class-name>org.foo.MyTransformerWithProperties</class-name>
<property key="transformerKey1" value="transformerValue1"/>
<property key="transformerKey2" value="transformerValue2"/>
</transformer>
```

Any transformer implementation needs to be added to the broker's classpath. See
the documentation on [adding runtime dependencies](using-server.md#adding-runtime-dependencies)
to understand how to make your transformer available to the broker.

0 comments on commit 111b9cc

Please sign in to comment.