WSO2 SP
Kafka Source
JSON attributes
Data Streaming
Event Processing

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.

Practice system design

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:

sql
1@Source(
2    type = 'kafka', 
3    topic.list = 'kafka_topic1,kafka_topic2', 
4    partition.no.list = '0,1', 
5    threading.option = 'single.thread', 
6    group.id = 'group1', 
7    bootstrap.servers = 'localhost:9092',
8    @map(type = 'json'))
9define stream KafkaInputStream (name string, age int);

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 (either single.thread or partition.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:

json
1{
2    "name": "John Doe",
3    "age": 30
4}

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:

BenefitDescription
ScalabilityHandles high throughput and scales well across a distributed architecture.
FlexibilitySupports multiple data formats and sources.
Real-Time ProcessingProcesses data in real time, suitable for time-sensitive data analysis.
ReliabilityKafka 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.