-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
layout: post | ||
title: Go SMT in Debezium | ||
date: 2025-02-24 12:00:00 +0100 | ||
tags: [ debezium, smt, go, tinygo, chicory, WebAssembly, wasm ] | ||
author: andreatp | ||
--- | ||
|
||
Change Data Capture (CDC) is a cornerstone of modern cloud-native architectures, enabling real-time event-driven applications. | ||
Debezium, a leading CDC platform, provides powerful Single Message Transformations (SMTs) to filter, route, and modify data streams before they reach their destination. | ||
|
||
While Debezium is a Java-based project, many cloud-native applications are built in Go. | ||
With this latest enhancement, you can now write SMT filters and routers in Go, allowing Go developers to fine-tune data processing within a Java technology thanks to https://tinygo.org/[TinyGo] and https://webassembly.org/[WebAssembly]. | ||
|
||
This blog post explores how to use Go plugins in Debezium, demonstrating how this feature enhances flexibility and customization for cloud-native teams. | ||
|
||
+++<!-- more -->+++ | ||
|
||
== Go SMT Filters and Routers in Debezium | ||
|
||
=== Introduction | ||
|
||
Change Data Capture (CDC) is at the heart of modern event-driven architectures, enabling applications to react to database changes in real-time. Debezium has long provided a robust set of Single Message Transformations (SMTs) to filter, route, and modify events before they reach their final destination. But what if you wanted to extend Debezium's capabilities using a language other than Java? | ||
|
||
With the latest enhancement, Debezium now allows developers to write SMT filters and routers in Go, opening up new possibilities for cloud-native applications. Since Go is widely used in cloud environments, this feature empowers teams to customize their CDC pipelines without leaving their primary development ecosystem. | ||
|
||
== Why Go for SMTs? | ||
|
||
Debezium runs on the JVM, and its SMTs have traditionally been Java-based, leveraging JSR 223. | ||
While this is great for Java developers, who might want to write filters in Groovy or similar, many teams building cloud-native applications rely on Go. With this new feature, you can now: | ||
|
||
- *Write SMT filters and routers in Go*, leveraging its simplicity, performance and type system. | ||
- *Avoid Java dependency overhead* when Go is your primary language you don't need to add extra jars to the classpath. | ||
- *Customize event processing logic* closer to your existing Go-based microservices. | ||
|
||
This makes it easier for Go developers to fine-tune how change events are filtered and routed without needing Java expertise. | ||
|
||
== How It Works | ||
|
||
The integration is based on Go plugins, allowing Debezium to dynamically load and execute Go-based SMTs. These plugins act as lightweight, customizable event processors that filter and route CDC events before they reach Kafka or another downstream system. | ||
|
||
Here's an example of how you can define a simple Go SMT filter: | ||
|
||
[source,go,filter.go] | ||
---- | ||
package main | ||
import ( | ||
"github.com/debezium/debezium-smt-go-pdk" | ||
) | ||
// Example filter function | ||
//export process | ||
func process(proxyPtr uint32) uint32 { | ||
var topicNamePtr = debezium.Get(proxyPtr, "topic") | ||
var topicName = debezium.GetString(topicNamePtr) | ||
return debezium.SetBool(topicName == "mytopic") | ||
} | ||
func main() {} | ||
---- | ||
|
||
This function should to be compiled with https://tinygo.org/[TinyGo]: | ||
|
||
[source,bash] | ||
---- | ||
tinygo build -ldflags='-extldflags --import-memory' --no-debug -target=wasm-unknown -o filter.wasm filter.go | ||
---- | ||
|
||
This function could be loaded as a plugin into Debezium, allowing the event processing pipeline to execute custom filtering logic in Go. | ||
A sample configuration on how to achieve this looks as follows: | ||
|
||
[source,none] | ||
---- | ||
transforms=filter | ||
transforms.filter.type=io.debezium.transforms.Filter | ||
transforms.filter.language=wasm.chicory | ||
transforms.filter.expression=file://filter.wasm | ||
---- | ||
|
||
== Where This Fits Best | ||
|
||
This feature is particularly useful for: | ||
|
||
- *Cloud-native applications* where Go is already the dominant language. | ||
- *Teams that want to extend Debezium without Java expertise.* | ||
- *Environments with lightweight deployments*, where Go's efficiency and lazy access to the data can help keep resource usage low. | ||
|
||
== A Glimpse into the Future | ||
|
||
While this feature currently focuses on Go-based SMTs, it also hints at a broader trend: enabling Debezium users to bring their own languages to the CDC processing pipeline. WebAssembly (Wasm) could further extend this concept, allowing transformations to be written in a variety of languages while maintaining portability and security. | ||
https://github.com/dylibso/chicory[Chicory] is being used as a zero dependencies Java Runtime for Wasm. | ||
|
||
For now, if you’re working with Go-based cloud-native systems and want to fine-tune your CDC pipeline, this new capability in Debezium is an exciting step forward. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.