Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON Demo DynamicDataSource Kafka

From Leeroopedia
Knowledge Sources
Domains Database, Messaging, Connection_Pooling
Last Updated 2026-10-14 00:00 GMT

Overview

Concrete tool for dynamically managing JDBC and Kafka data sources at runtime in the APIJSON Kafka multi-datasource demo.

Description

The DynamicDataSource class (Kafka variant) is a Spring @Component implementing ApplicationRunner that manages a static map of data source details including Kafka producer properties. On startup, it initializes JDBC connection pools and Kafka producer configuration. It provides addDataSource for runtime addition and getDetail for lookup by datasource name, returning Kafka Properties for producer configuration.

Usage

Use this class when the APIJSON Kafka demo needs to dynamically resolve JDBC or Kafka datasource connection details.

Code Reference

Source Location

Signature

@Data
@Order(value = 10)
@Component
@Slf4j
public class DynamicDataSource implements ApplicationRunner {
    private static Map<String, DynamicDataSource> dataSourceMap = new HashMap<>();
    private String datasourceName;
    private String url;
    private String dbAccount;
    private String dbPassword;
    private Properties props;  // Kafka producer properties

    public static void addDataSource(DynamicDataSource detail);
    public static DynamicDataSource getDetail(String datasource);
    @Override
    public void run(ApplicationArguments args) throws Exception;
}

Import

import apijson.demo.DynamicDataSource;

I/O Contract

See Implementation:APIJSON_APIJSON_Demo_DynamicJdbcDataSource for the I/O contract pattern; the Kafka variant adds Properties props for Kafka producer config.

Usage Examples

// Get Kafka producer properties
DynamicDataSource ds = DynamicDataSource.getDetail("kafka");
Properties props = ds.getProps();
// Use props to create KafkaProducer

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment