Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hden/debezium-server-name-mapper

Custom Topic Name Mapper for Debezium Server
https://github.com/hden/debezium-server-name-mapper

Last synced: 28 days ago
JSON representation

Custom Topic Name Mapper for Debezium Server

Awesome Lists containing this project

README

        

# Custom Topic Name Mapper

Forked from: https://github.com/debezium/debezium-examples/tree/main/debezium-server-name-mapper (Apache Pulsar with PrefixingNameMapper)

This example demonstrates how to develop and deploy a bean that would allow the developer to implement a custom topic naming policy.

The implementation of the custom naming policy is in the class `ConstantNameMapper`.
The class is marked as `@Dependent` and it is injected into the configured sink adaptor class.
It exposes a configuration option named `mapper.constant` which defines a string that is inserted before the original topic name.

The configuration option is configured either via `application.properties` configuration file or via other ways defined in the Microprofile Config specification, e.g. an environment variable.

As an example, when setting `mapper.constant` to the value `foobar`, then a message intended to be delivered to the topic `server.schema.table` would be routed to topic `foobar`.

## Topology

This demo uses Pub/Sub as the sink and the standard Debezium example PostgreSQL database.
Both Pub/Sub Emulator and the source database are deployed via Docker Compose file.

## How to run

From terminal start the source database and the sink system:

```
$ export DEBEZIUM_VERSION=2.7
$ docker compose up
```

In another terminal build the custom naming policy class and the runner JAR to start the application:

```
$ mvn clean install
```

Create a topic (`foobar`) and a subscription (`baz`):

```
./init.sh
```

Start the application:

```
$ java -jar target/quarkus-app/quarkus-run.jar
```

In another terminal pull a event from the subscription:

```
./pull.sh
```

The resulting topic list should contain for example a topic named

```
{
"receivedMessages": [{
"ackId": "projects/emulator/subscriptions/baz:1",
"message": {
"data": "eyJzY2hlbWEiOnsidHlwZSI6InN0cnVjdCIsImZpZWxkcyI6W3sidHlwZSI6InN0cnVjdCIsImZpZWxkcyI6W3sidHlwZSI6ImludDMyIiwib3B0aW9uYWwiOmZhbHNlLCJkZWZhdWx0IjowLCJmaWVsZCI6ImlkIn0seyJ0eXBlIjoic3RyaW5nIiwib3B0aW9uYWwiOmZhbHNlLCJmaWVsZCI6Im5h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GlvbiI6bnVsbCwib3AiOiJyIiwidHNfbXMiOjE3MjM3MzI5MTQ2NjUsInRzX3VzIjoxNzIzNzMyOTE0NjY1Nzg1LCJ0c19ucyI6MTcyMzczMjkxNDY2NTc4NTAwMH19",
"messageId": "2",
"publishTime": "2024-08-15T14:41:55.370Z",
"orderingKey": "{\"schema\":{\"type\":\"struct\",\"fields\":[{\"type\":\"int32\",\"optional\":false,\"default\":0,\"field\":\"id\"}],\"optional\":false,\"name\":\"tutorial.inventory.products.Key\"},\"payload\":{\"id\":104}}"
}
}]
}
```