|
| 1 | += Plugins |
| 2 | +:description: Create and load dynamic plugins at runtime with gRPC. |
| 3 | +:page-categories: Development, Stream Processing |
| 4 | +:page-toclevels: 3 |
| 5 | + |
| 6 | +Redpanda Connect's RPC plugin framework is a powerful Apache 2.0 licensed feature that takes data streaming flexibility to the next level. By enabling you to create and load plugins at runtime using any programming language that supports gRPC, this framework opens up a world of new integration possibilities beyond Go. Whether you need to leverage specialized libraries, integrate with AI/ML tools, or build custom components in your preferred language, Redpanda Connect plugins provide the extensibility and interoperability to make it happen. |
| 7 | + |
| 8 | +== Plugin types |
| 9 | + |
| 10 | +Redpanda Connect supports two types of plugins: |
| 11 | + |
| 12 | +Compiled plugins:: Built in Go and compiled directly into the Redpanda Connect binary. These offer maximum performance for critical workloads. |
| 13 | + |
| 14 | +Dynamic plugins:: External executables that communicate with Redpanda Connect via gRPC. These provide language flexibility and can be loaded at runtime without rebuilding the binary. |
| 15 | + |
| 16 | +This documentation focuses on dynamic plugins. |
| 17 | + |
| 18 | +== When to use dynamic plugins |
| 19 | + |
| 20 | +Dynamic plugins are ideal when you need to extend Redpanda Connect's capabilities without the constraints of Go. Use cases include: |
| 21 | + |
| 22 | +* Use existing libraries not available in Go |
| 23 | +* Write plugins in languages other than Go (such as Python) |
| 24 | +* Add plugins without rebuilding the entire Redpanda Connect binary |
| 25 | +* Deploy plugins independently of your main Redpanda Connect deployment |
| 26 | +* Integrate with AI/ML frameworks, data science libraries, or specialized tools |
| 27 | + |
| 28 | +== Architecture |
| 29 | + |
| 30 | +Dynamic plugins run as separate processes and communicate with the main Redpanda Connect process through gRPC over Unix sockets. This architecture provides the following benefits: |
| 31 | + |
| 32 | +* Process isolation: Plugin crashes don't affect the main engine. |
| 33 | +* Language agnostic: Support for any language with gRPC libraries. |
| 34 | +* Modular design: Each plugin maps to a single subprocess. |
| 35 | +* Battle-tested communication. Uses proven gRPC technology. |
| 36 | + |
| 37 | +The system includes three compiled plugin wrappers (one for each component type: `BatchInput`, `BatchProcessor`, and `BatchOutput`) that handle the communication with external plugin executables. |
| 38 | + |
| 39 | +== Supported languages |
| 40 | + |
| 41 | +Redpanda Connect currently provides the following SDKs: |
| 42 | + |
| 43 | +* **Go**: Familiar environment for existing Redpanda Connect developers with type-safe interfaces |
| 44 | +* **Python**: Access to rich ecosystem including PyTorch, TensorFlow, Hugging Face Transformers, LangChain, Pandas, and NumPy |
| 45 | + |
| 46 | +== Performance considerations |
| 47 | + |
| 48 | +Dynamic plugins introduce some serialization and IPC overhead compared to compiled plugins. To minimize performance impact: |
| 49 | + |
| 50 | +* The system uses batch components exclusively to amortize cross-process communication costs. |
| 51 | +* Each plugin runs in a separate process with predictable resource usage. |
| 52 | +* For maximum performance in critical workloads, use compiled plugins instead. |
| 53 | + |
| 54 | +== Prerequisites |
| 55 | + |
| 56 | +Before creating dynamic plugins, ensure you have: |
| 57 | + |
| 58 | +* Redpanda Connect v4.56.0 or later |
| 59 | +* Python environment (for Python plugins) |
| 60 | +* Required language SDKs installed |
| 61 | + |
| 62 | +=== Install Redpanda Connect |
| 63 | + |
| 64 | +Verify your version, and upgrade if necessary: |
| 65 | + |
| 66 | +[source,shell] |
| 67 | +---- |
| 68 | +rpk --version |
| 69 | +rpk connect upgrade |
| 70 | +---- |
| 71 | + |
| 72 | +== Create your first plugin |
| 73 | + |
| 74 | +This example demonstrates creating a simple FizzBuzz processor plugin in Python. |
| 75 | + |
| 76 | +=== Step 1: Set up the environment |
| 77 | + |
| 78 | +[source,shell] |
| 79 | +---- |
| 80 | +# Create a new directory for your plugin |
| 81 | +mkdir fizzbuzz_plugin |
| 82 | +cd fizzbuzz_plugin |
| 83 | +
|
| 84 | +# Initialize with link:https://docs.astral.sh/uv/[uv] (or use pip/conda) |
| 85 | +uv init . |
| 86 | +uv add redpanda_connect |
| 87 | +---- |
| 88 | + |
| 89 | +=== Step 2: Download the example |
| 90 | + |
| 91 | +[source,shell] |
| 92 | +---- |
| 93 | +# Download the example processor |
| 94 | +curl -o fizzbuzz_processor.py \ |
| 95 | + https://raw.githubusercontent.com/redpanda-data/connect/main/public/plugin/python/examples/fizzbuzz_processor.py |
| 96 | +---- |
| 97 | + |
| 98 | +=== Step 3: Create the plugin configuration |
| 99 | + |
| 100 | +Create `plugin.yaml`: |
| 101 | + |
| 102 | +[source,yaml] |
| 103 | +---- |
| 104 | +name: fizzbuzz |
| 105 | +summary: Transforms numbers according to FizzBuzz rules (3=Fizz, 5=Buzz, 15=FizzBuzz) |
| 106 | +command: ["uv", "run", "fizzbuzz_processor.py"] |
| 107 | +type: processor |
| 108 | +fields: [] |
| 109 | +---- |
| 110 | + |
| 111 | +=== Step 4: Create the pipeline configuration |
| 112 | + |
| 113 | +Create `connect.yaml`: |
| 114 | + |
| 115 | +[source,yaml] |
| 116 | +---- |
| 117 | +input: |
| 118 | + generate: |
| 119 | + interval: 1s |
| 120 | + mapping: | |
| 121 | + root = counter() % 20 + 1 # Generate numbers 1-20 |
| 122 | +
|
| 123 | +pipeline: |
| 124 | + processors: |
| 125 | + - fizzbuzz: {} |
| 126 | +
|
| 127 | +output: |
| 128 | + stdout: |
| 129 | + codec: lines |
| 130 | +---- |
| 131 | + |
| 132 | +=== Step 5: Run the plugin |
| 133 | + |
| 134 | +Execute the pipeline with your dynamic plugin: |
| 135 | + |
| 136 | +[source,shell] |
| 137 | +---- |
| 138 | +rpk connect run --rpc-plugins=plugin.yaml connect.yaml |
| 139 | +---- |
| 140 | + |
| 141 | +Expected output: |
| 142 | +[source,text] |
| 143 | +---- |
| 144 | +1 |
| 145 | +2 |
| 146 | +Fizz |
| 147 | +4 |
| 148 | +Buzz |
| 149 | +Fizz |
| 150 | +7 |
| 151 | +8 |
| 152 | +Fizz |
| 153 | +Buzz |
| 154 | +11 |
| 155 | +Fizz |
| 156 | +13 |
| 157 | +14 |
| 158 | +FizzBuzz |
| 159 | +16 |
| 160 | +17 |
| 161 | +Fizz |
| 162 | +19 |
| 163 | +Buzz |
| 164 | +---- |
| 165 | + |
| 166 | +== Python plugin development |
| 167 | + |
| 168 | +=== Basic processor structure |
| 169 | + |
| 170 | +Python processors use the `@redpanda_connect.processor` decorator: |
| 171 | + |
| 172 | +[source,python] |
| 173 | +---- |
| 174 | +import asyncio |
| 175 | +import logging |
| 176 | +import redpanda_connect |
| 177 | +
|
| 178 | +@redpanda_connect.processor |
| 179 | +def transform_message(msg: redpanda_connect.Message) -> redpanda_connect.Message: |
| 180 | + # Your transformation logic here |
| 181 | + msg.payload = msg.payload.upper() |
| 182 | + return msg |
| 183 | +
|
| 184 | +if __name__ == "__main__": |
| 185 | + logging.basicConfig(level=logging.INFO) |
| 186 | + asyncio.run(redpanda_connect.processor_main(transform_message)) |
| 187 | +---- |
| 188 | + |
| 189 | +=== Plugin configuration structure |
| 190 | + |
| 191 | +Each plugin requires a configuration file with the following structure: |
| 192 | + |
| 193 | +[source,yaml] |
| 194 | +---- |
| 195 | +name: <plugin-name> |
| 196 | +summary: <brief-description> |
| 197 | +command: ["<executable>", "<args>"] |
| 198 | +type: <processor|input|output> |
| 199 | +fields: [] # Configuration fields (if any) |
| 200 | +---- |
| 201 | + |
| 202 | +=== Message handling |
| 203 | + |
| 204 | +The Python SDK provides access to message properties: |
| 205 | + |
| 206 | +* `msg.payload` - Message content |
| 207 | +* `msg.metadata` - Message metadata |
| 208 | +* Standard message transformation methods |
| 209 | + |
| 210 | +== Next steps |
| 211 | + |
| 212 | +* Explore the https://github.com/redpanda-data/connect/tree/main/public/plugin/python/examples[example plugins^] in the Redpanda Connect repository |
| 213 | +* Join the https://redpanda.com/slack[Redpanda Community Slack^] to discuss plugin development |
| 214 | +* Review the https://github.com/redpanda-data/connect[Redpanda Connect source code^] for advanced use cases |
| 215 | + |
| 216 | +== Related topics |
| 217 | + |
| 218 | +* xref:components:about.adoc[Components overview] |
| 219 | +* xref:configuration:about.adoc[Configuration overview] |
| 220 | +* xref:guides:getting_started.adoc[Getting started with Redpanda Connect] |
0 commit comments