Transformers

A transformer, 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 and core bridges support.

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

  1. public interface Transformer {
  2. default void init(Map<String, String> properties) { }
  3. Message transform(Message message);
  4. }

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.:

  1. <transformer-class-name>
  2. org.foo.MyTransformer
  3. </transformer-class-name>

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

  1. <transformer>
  2. <class-name>org.foo.MyTransformerWithProperties</class-name>
  3. <property key="transformerKey1" value="transformerValue1"/>
  4. <property key="transformerKey2" value="transformerValue2"/>
  5. </transformer>

Any transformer implementation needs to be added to the broker’s classpath. See the documentation on adding runtime dependencies to understand how to make your transformer available to the broker.