Kafka
Manage real-time event streams with Kafka
medusa-plugin-kafka
Warning: This plugin is currently under development and may be unstable.
Copy to clipboardmedusa-plugin-kafka
is a Kafka integration plugin for MedusaJS. This plugin connects to specified Kafka brokers and forwards events triggered in the MedusaJS application to configured Kafka topics, allowing real-time integration of your e-commerce platform with other systems.
For more details on event integration, visit the Medusa Event Documentation.
Features
- Customizable Topic Prefixes: Define prefixes for topics to help categorize and route messages appropriately.
- Event Subscription: Subscribe to specific or all Medusa events and configure individual processing rules for each.
- Data Transformation: Transform event data before sending it to Kafka, ensuring that only relevant information is forwarded.
- Merge Events: Allows writing multiple events to the same topic. For example, product and product variant events can be written to the same topic. If Copy to clipboard
bulk
is true, all values are added individually to the topic instead of as an array.
Installation
To install the plugin, navigate to your MedusaJS project directory and run the following command:
1npm install medusa-plugin-kafka
Configuration
Add the following configuration to your Copy to clipboardmedusa-config.js
to integrate the Kafka plugin with your Medusa store:
1234567891011121314151617181920{resolve: "medusa-plugin-kafka",/** @type {import('medusa-plugin-kafka').PluginOptions} */options: {brokers: ['127.0.0.1:9092'], // List of Kafka brokerstopicPrefix: 'prefix.', // Prefix for Kafka topicslogLevel: 4, // Logging levelsubscribeAll: false, // Subscribe to all Medusa eventsmerge: [{ignorePrefix: true,topic: 'store.product',events: {'product-variant.created': {transform: async (document, container) => await productVariantTransform(document, container)},'product-variant.updated': {transform: async (document, container) => await productVariantTransform(document, container)},'product.updated': {
1234567891011121314151617181920const productTransform =async (document, container) => {let data = document;/** @type {import('@medusajs/medusa').ProductService} */const productService = container.resolve('productService');const rawData = await productService.retrieve(data.id, {relations: ["variants","variants.prices","variants.options","images","options","tags","type","collection","categories","categories.category_children","categories.parent_category"],
Usage
Once configured, the plugin will automatically start listening for the configured events and send the transformed data to the specified Kafka topics. Ensure that your Kafka instance is running and accessible from your Medusa server.
Development and Testing
This plugin is currently in beta. Developers are encouraged to contribute to testing and enhancing its functionality. Please report any issues or contribute suggestions via GitHub issues.
Contributing
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change. Ensure to update tests as appropriate.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.