Implementation:APIJSON APIJSON Demo DemoSQLExecutor Kafka
| Knowledge Sources | |
|---|---|
| Domains | Messaging, Kafka, SQL_Execution |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete tool for intercepting POST operations to route inserts to Kafka as message production instead of SQL inserts.
Description
The DemoSQLExecutor class (Kafka variant) extends APIJSONSQLExecutor<String> and overrides executeUpdate to detect the Kafka datasource. When the datasource is "kafka" and the method is POST, it extracts the message column from the request values and sends it to Kafka via KafkaSimpleProducer.sendMessage. For non-Kafka datasources, it falls back to standard JDBC execution.
Usage
Use this class when the APIJSON Kafka demo needs to produce messages to Kafka topics via APIJSON POST requests.
Code Reference
Source Location
- Repository: APIJSON_APIJSON_Demo
- File: APIJSON-Java-Server/APIJSONDemo-MultiDataSource-Kafka/src/main/java/apijson/demo/DemoSQLExecutor.java
- Lines: 1-130
Signature
@Log4j2
public class DemoSQLExecutor extends APIJSONSQLExecutor<String> {
@Override
public Connection getConnection(SQLConfig config) throws Exception;
@Override
public int executeUpdate(@NotNull SQLConfig config, String sql) throws Exception;
}
Import
import apijson.demo.DemoSQLExecutor;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | SQLConfig | Yes | SQL config with datasource="kafka"
|
| sql | String | Yes | Generated SQL (used for non-Kafka fallback) |
Outputs
| Name | Type | Description |
|---|---|---|
| executeUpdate() returns | int | Number of messages sent (1 on success) |
Usage Examples
Send Message to Kafka via APIJSON
// APIJSON POST to Kafka datasource
{
"kafka_topic": {
"message": "Hello Kafka from APIJSON"
}
}
// DemoSQLExecutor intercepts and sends to Kafka producer