广播表

广播表 Java API 规则配置允许用户直接通过编写 Java 代码的方式,完成 ShardingSphereDataSource 对象的创建,Java API 的配置方式非常灵活,不需要依赖额外的 jar 包就能够集成各种类型的业务系统。

参数解释

类名称:org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration

可配置属性:

名称数据类型说明默认值
tables (+)Collection<String>广播表规则配置

配置示例

广播表 Java API 配置示例如下:

  1. public final class ShardingDatabasesAndTablesConfigurationPrecise {
  2. @Override
  3. public DataSource getDataSource() throws SQLException {
  4. return ShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Arrays.asList(createBroadcastRuleConfiguration()), new Properties());
  5. }
  6. private Map<String, DataSource> createDataSourceMap() {
  7. Map<String, DataSource> result = new HashMap<>();
  8. result.put("demo_ds_0", DataSourceUtil.createDataSource("demo_ds_0"));
  9. result.put("demo_ds_1", DataSourceUtil.createDataSource("demo_ds_1"));
  10. return result;
  11. }
  12. private BroadcastRuleConfiguration createBroadcastRuleConfiguration() {
  13. return new BroadcastRuleConfiguration(Collections.singletonList("t_address"));
  14. }
  15. }

相关参考