How to use WireTap EIP using Apache Camel | Enterprise Integration Patterns

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.jss</groupId>
<artifactId>camel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>camel</name>
<description>Apache Camel with Spring Boot</description>

<properties>
<java.version>1.8</java.version>
<junit.platform.version>1.6.0</junit.platform.version>
<camel.version>3.7.3</camel.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<scope>test</scope>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rabbitmq</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.12</version>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-junit5</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

CamelApplication.java

package com.jss.camel;

import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
public class CamelApplication {
@Autowired
ProducerTemplate producerTemplate;

public static void main(String[] args) {
SpringApplication.run(CamelApplication.class, args);
}
}

Wiretap.java

package com.jss.camel.components;

import com.jss.camel.TransactionDto;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.apache.camel.support.DefaultMessage;
import org.springframework.stereotype.Component;

import java.util.Date;

import static org.apache.camel.LoggingLevel.ERROR;

@Component
public class Wiretap extends RouteBuilder {

public static final String SENDER = "sender";
public static final String RECEIVER = "receiver";
public static final String AUDIT_TRANSACTION_ROUTE = "direct:audit-transaction";
public static final String AUDIT = "audit-transactions";
static final String RABBIT_URI = "rabbitmq://localhost:5672/amq.direct?queue=%s&routingKey=%s&autoDelete=false";

@Override
public void configure() throws Exception {
fromF(RABBIT_URI, SENDER, SENDER)
.unmarshal().json(JsonLibrary.Jackson, TransactionDto.class)
.wireTap(AUDIT_TRANSACTION_ROUTE)
.process(this::enrichTransactionDto)
.marshal().json(JsonLibrary.Jackson, TransactionDto.class)
.toF(RABBIT_URI, RECEIVER, RECEIVER)
.log(ERROR, "Money Transferred: ${body}")
;

from(AUDIT_TRANSACTION_ROUTE)
.process(this::enrichTransactionDto)
.marshal().json(JsonLibrary.Jackson, TransactionDto.class)
.toF(RABBIT_URI, AUDIT, AUDIT);
}

private void enrichTransactionDto(Exchange exchange) {
TransactionDto dto = exchange.getMessage().getBody(TransactionDto.class);
dto.setTransactionDate(new Date().toString());

Message message = new DefaultMessage(exchange);
message.setBody(dto);
exchange.setMessage(message);
}
}