Skip to main content
Loading

Message Transformer for Aerospike XDR Proxy

caution
  • This config is only valid for the XDR Proxy version 2.1.0+.
  • Bin convergence and writing bin-level LUT (last update time) are not supported in the custom message transformer.

The Message Transformer allows you to write custom code that reads incoming XDR Change Notification Records, performs Aerospike operations or other transformations on them, and converts them into AerospikeRecordOperation objects. You can develop your code by using the Java SDK, then bundle it as a .jar file. You then make the .jar file available to the XDR Proxy using the classpath, along with associated parameters that are specified in the configuration file. Your custom code can be plugged into the XDR Proxy for rapid integration.

Example use casesโ€‹

  • Perform complex operations on maps or lists on XDR CNR (change notification record) before writing the output Aerospike records to your Aerospike databases. For example, you could add an element from incoming messages to maps or lists, or create maps of maps.
  • Filter messages for compliance use cases. For example, you can filter out records containing Personally Identifiable Information (PII), or you can mask fields with sensitive data prior to writing records to an Aerospike database.
  • Create Aerospike records with bins generated by tweaking XDR CNR (change notification record) values. You can even extend your message transformer to create Aerospike keys.

What does it not do?โ€‹

  • The message transformer is not meant for heavy-weight processing or calling external APIs.
  • It does not support multi-record transactions. However, it supports multiple operations on the same record, as well as reads from the database during the transformation.

Developing a message transformerโ€‹

Add the Maven SDK dependenciesโ€‹

Add the following dependencies:

<dependencies>
<!-- Aerospike Inbound SDK -->
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-connect-inbound-sdk</artifactId>
<version>1.2.0</version>
<scope>provided</scope> <!-- Will be available in the XDR Proxy runtime -->
</dependency>

<!-- Aerospike Outbound SDK -->
<dependency>
<groupId>com.aerospike</groupId>
<artifactId>aerospike-connect-outbound-sdk</artifactId>
<version>2.2.0</version>
<scope>provided</scope> <!-- Will be available in the XDR Proxy runtime -->
</dependency>

<!-- Javax inject annotations -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope> <!-- Will be available in the XDR Proxy runtime -->
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.33</version>
<scope>provided</scope> <!-- Will be available in the XDR Proxy runtime -->
</dependency>
</dependencies>

Implement the InboundMessageTransformer interfaceโ€‹

The custom message transformer should implement InboundMessageTransformer<InboundMessage<Key, ChangeNotificationRecord>>

caution

The bins field in ChangeNotificationRecord is an immutable map.

The WritePolicy passed in the InboundMessage to the custom message transformer is as follows:

Write Policy fieldDescription
recordExistsActionSet to the value shipped by XDR
generationPolicySet to the value shipped by XDR
generationSet to the value shipped by XDR
expirationSet to the value shipped by XDR
socketTimeoutSet to the value configured in the aerospike section of the YAML config
totalTimeoutSet to the value configured in the aerospike section of the YAML config
xdrSet to true

You have the option to inject the following objects in your message-transformer class using Java Dependency Injection.

ClassUsage
AerospikeReaderAn object to read a record from the Aerospike Database.
InboundMessageTransformerConfigThe custom parameters provided in the configuration file as params.

Thread safetyโ€‹

  • If you annotate your implementation with @Singleton, it has to be thread safe because one instance can be used by multiple threads.
  • If you do not annotate your implementation with @Singleton, a new instance of your message transformer is created for every incoming message.

Configure the XDR Proxy to use your message transformerโ€‹

Include the message-transformer stanza at the global, namespace, or set scope.

Exampleโ€‹

# Message transformer at global scope.
message-transformer:
class: com.aerospike.GlobalScopeTransformer
params:
color: RED

namespaces:
milkyWay:
# Message transformer at namespace "milkyWay" scope.
message-transformer:
class: com.aerospike.TestNamespaceTransformer
params:
color: BLUE
sets:
solarSystem:
# Message transformer at set "solarSystem" scope.
message-transformer:
class: com.aerospike.TestNamespaceTransformer
params:
color: YELLOW

Deploy your message transformerโ€‹

Deploy your .jar file, along with any dependencies it might have, by copying it to the /opt/aerospike-xdr-proxy/usr-lib/ folder of the directory where the Aerospike XDR Proxy is installed.

Look through example transformersโ€‹

See here for a few examples of Message Transformers for XDR Proxy.