TL;DR
-
MysqlRouteSrv@v1.0.0enablesexternaldbthroughsystem.components=externaldb. - Service-level
extdb.*config is loaded fromservice.config.propertiesand can override common defaults. - Dynamic datasource beans are registered as
extdb-<id>-datasourceand consumed by Camel SQL endpoints. - The built-in timer route verifies connectivity through
select/insert/query/deleteagainsttestexdb.
Metadata
- Applicable Version:
MysqlRouteSrv@v1.0.0 - Related Service:
MysqlRouteSrv@v1.0.0@mysql-healthcheck-route.xml
Background and Goal
When teams deploy multiple services, database endpoints and credentials often vary by environment and by route. Hardcoding datasource names in XML routes increases change cost and risk.
externaldb addresses this by moving database target selection to service config:
- Keep route SQL logic stable.
- Register datasources dynamically in Camel Registry.
- Switch route target datasource by properties instead of route rewrites.
For MysqlRouteSrv v1.0.0, this mechanism is used to validate MySQL connectivity and basic CRUD flow on a fixed schedule.
Route and Configuration Breakdown
1) Component enablement and config priority
From lightesb-camel-app/MysqlRouteSrv/v1.0.0/common.config.properties:
system.components=externaldb
From lightesb-camel-app/MysqlRouteSrv/v1.0.0/service.config.properties:
extdb.enabled=true
extdb.default=primary
extdb.ids=primary
extdb.primary.type=mysql
extdb.primary.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
extdb.primary.driver=com.mysql.cj.jdbc.Driver
extdb.primary.username=root
extdb.primary.password=nghxni
extdb.primary.maxPoolSize=10
mysqlroute.target.datasource=primary
Configuration model:
-
common.config.properties: common defaults -
service.config.properties: service-level override - Effective priority: service-level settings override common settings
2) Dynamic Bean names in Camel Registry
After externaldb is loaded, the following beans are available:
-
extdb-<id>-datasource(for exampleextdb-primary-datasource) extdb-default-datasourceextdb.configextdb.route.targets
This naming contract allows route-level datasource switching with placeholders.
3) Timer route wiring with SQL component
From mysql-healthcheck-route.xml:
<from uri="timer://mysql-healthcheck?fixedRate=true&period=60000"/>
<setHeader name="db.target">
<simple>{{mysqlroute.target.datasource}}</simple>
</setHeader>
<to uri="sql:select 1 as db_ok?dataSource=#bean:extdb-{{mysqlroute.target.datasource}}-datasource&outputType=SelectOne"/>
The same datasource reference pattern is reused for:
insert into testexdb (...)select ... from testexdb where ID=:#IDdelete from testexdb where ID=:#ID
This keeps SQL routes stable while allowing datasource redirection in config.
Request and Response Examples
MysqlRouteSrv v1.0.0 is a timer-driven route (HTTP.Listener=false), so runtime validation is based on startup and route logs.
1) Start the service process
..\start.bat
Run ..\start.bat from the lightesb-camel directory to start the service, then continue with the log checks below.
2) Verify route execution logs
Expected output pattern (based on logs/mysql-healthcheck-route.log):
- health check starts with
target=primary -
select 1returnsresult=1 - insert/query/delete against
testexdbcomplete successfully
3) Verify datasource target switching
Change:
mysqlroute.target.datasource=primary
to:
mysqlroute.target.datasource=archive
Then reload and check logs again. The target=... field should follow the new datasource id when extdb.archive.* is configured.
Common Issues and Troubleshooting
1) No bean could be found in the registry
Check:
-
system.componentsincludesexternaldb extdb.enabled=true- target id exists in
extdb.ids - SQL URI name matches
extdb-{{xxx.target.datasource}}-datasource
2) Health check runs but SQL fails
Check:
- MySQL URL/driver/user/password are valid
- target table
testexdbexists in the selected schema - account has
insert/select/deletepermissions
3) Datasource switch does not take effect
Check:
- the new id is fully configured as
extdb.<id>.* - service reload has completed
- route header
db.targetprints the expected id in logs
4) Unexpected default datasource behavior
Check:
-
extdb.defaultvalue -
mysqlroute.target.datasourceroute-level override
If route-level override is missing, default id may be used.
Summary
MysqlRouteSrv v1.0.0 provides a practical baseline for External Database support in LightESB:
- component-level enablement (
externaldb) - service-level datasource model (
extdb.*) - dynamic Camel Registry binding (
extdb-<id>-datasource) - stable SQL routes with config-driven target selection
This pattern is a good fit for teams that need one route implementation but multiple environment-specific database targets.
Top comments (0)