WSO2 SP - Kafka source with JSON attributes
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
WSO2 Stream Processor (WSO2 SP) is a powerful tool for processing real-time event streams. It is part of the WSO2 middleware stack but can be integrated with external systems like Apache Kafka. Apache Kafka, on the other hand, is a widely used open-source stream-processing software platform developed by Linkedin and written in Scala and Java, which functions on the publish-subscribe model. Merging these technologies enables handling complex event processing with high throughput and low latency.
Integrating WSO2 SP with Kafka
WSO2 SP can integrate with Kafka as a source, which allows WSO2 SP to consume messages from a Kafka cluster. This is particularly useful in scenarios where events are generated at a high velocity and volume, such as monitoring networks, tracking user activities on websites, or analyzing financial transactions.
Configuring Kafka as a Source in WSO2 SP
To configure Kafka as a source, WSO2 SP uses a Kafka source type in its Siddhi application. Siddhi is the event processing language of WSO2 SP. Below is the basic configuration syntax to define a Kafka source within a Siddhi application:
In this configuration:
type: Specifies the source type which is 'kafka'.topic.list: Kafka topics from which the messages are consumed.partition.no.list: Specifies the partitions of the topics.threading.option: Determines how the partitions are consumed (eithersingle.threadorpartition.wise).group.id: Kafka consumer group ID.bootstrap.servers: Specifies the address of the Kafka server.
Mapping JSON Attributes
When messages in Kafka are formatted in JSON, you must specify how these messages are parsed and mapped to the defined stream attributes in Siddhi. The @map(type = 'json') annotation in the source configuration handles this task.
For instance, if Kafka is pushing the following JSON message:
The above Siddhi stream definition will parse the JSON and map the name and age attributes to the respective fields in the KafkaInputStream stream.
Use Cases of WSO2 SP with Kafka
The integration of WSO2 SP and Kafka can be used in numerous scenarios like:
- Real-Time Analytics: Analyze data (e.g., user clicks or IoT sensor data) in real time.
- Monitoring and Alerting: Use streams for monitoring applications and trigger alerts based on specific conditions.
- Data Aggregation: Aggregate data from various sources within Kafka for complex processing.
Advantages of Using WSO2 SP with Kafka
Here's a table summarizing the benefits of integrating WSO2 SP with Kafka:
| Benefit | Description |
| Scalability | Handles high throughput and scales well across a distributed architecture. |
| Flexibility | Supports multiple data formats and sources. |
| Real-Time Processing | Processes data in real time, suitable for time-sensitive data analysis. |
| Reliability | Kafka ensures data durability and replication. |
Conclusion
Integrating WSO2 SP with Kafka provides powerful capabilities for processing streams of data in real time. By leveraging Kafka as a source in WSO2 SP, organizations can develop sophisticated stream processing applications that are scalable, reliable, and efficient. With the ability to process and analyze data as it's being generated, businesses can gain invaluable insights quickly, enabling more informed decision-making and agile responses to market dynamics.
Related reading
- ZeroMQ - Handling slow receivers without dropping
- ZeroMQ / 0mq or nanomsg bindings to Kafka?
- ZeroMQ can subscribe, but how to exclude a specific filter?
- ZeroMQ Publish and Subscribe concurrently
- ZeroMQ PUB/SUB topology on the same machine
- ZeroMQ vs Oracle queuing
- Zookeeper-Kafka and Consistent hashing
- ZooKeeper - clients co-ordination after one or more client lose connection with ZooKeeper

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.