Java Code Examples for io.debezium.config.Configuration#Builder

The following examples show how to use io.debezium.config.Configuration#Builder . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestHelper.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a default configuration suitable for most test cases. Can be amended/overridden in individual tests as
 * needed.
 */
public static Configuration.Builder defaultConfig() {
    JdbcConfiguration jdbcConfiguration = defaultJdbcConfig();
    Configuration.Builder builder = Configuration.create();

    jdbcConfiguration.forEach(
            (field, value) -> builder.with(Db2ConnectorConfig.DATABASE_CONFIG_PREFIX + field, value));

    return builder.with(RelationalDatabaseConnectorConfig.SERVER_NAME, "testdb")
            .with(Db2ConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
            .with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
            .with(RelationalDatabaseConnectorConfig.INCLUDE_SCHEMA_CHANGES, false);
}
 
Example 2
Source File: TestHelper.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a default configuration suitable for most test cases. Can be amended/overridden in individual tests as
 * needed.
 */
public static Configuration.Builder defaultConfig() {
    JdbcConfiguration jdbcConfiguration = defaultJdbcConfig();
    Configuration.Builder builder = Configuration.create();

    jdbcConfiguration.forEach(
            (field, value) -> builder.with(OracleConnectorConfig.DATABASE_CONFIG_PREFIX + field, value));

    return builder.with(RelationalDatabaseConnectorConfig.SERVER_NAME, SERVER_NAME)
            .with(OracleConnectorConfig.PDB_NAME, "ORCLPDB1")
            .with(OracleConnectorConfig.XSTREAM_SERVER_NAME, "dbzxout")
            .with(OracleConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class)
            .with(FileDatabaseHistory.FILE_PATH, DB_HISTORY_PATH)
            .with(RelationalDatabaseConnectorConfig.INCLUDE_SCHEMA_CHANGES, false);
}
 
Example 3
Source File: TestHelper.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
private static Configuration.Builder testConfig() {
    JdbcConfiguration jdbcConfiguration = testJdbcConfig();
    Configuration.Builder builder = Configuration.create();

    jdbcConfiguration.forEach(
            (field, value) -> builder.with(OracleConnectorConfig.DATABASE_CONFIG_PREFIX + field, value));

    return builder;
}
 
Example 4
Source File: TestHelper.java    From debezium-incubator with Apache License 2.0 5 votes vote down vote up
private static Configuration.Builder adminConfig() {
    JdbcConfiguration jdbcConfiguration = adminJdbcConfig();
    Configuration.Builder builder = Configuration.create();

    jdbcConfiguration.forEach(
            (field, value) -> builder.with(OracleConnectorConfig.DATABASE_CONFIG_PREFIX + field, value));

    return builder;
}
 
Example 5
Source File: DebeziumToPubSubDataSender.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
public DebeziumToPubSubDataSender(
    String databaseName,
    String userName,
    String userPassword,
    String databaseAddress,
    Integer databasePort,
    String gcpProject,
    String gcpPubsubTopicPrefix,
    String offsetStorageFile,
    String databaseHistoryFile,
    Boolean inMemoryOffsetStorage,
    Boolean singleTopicMode,
    Set<String> whitelistedTables,
    String rdbms,
    org.apache.commons.configuration2.ImmutableConfiguration debeziumConfig) {

  this.userName = userName;
  this.userPassword = userPassword;
  this.databaseAddress = databaseAddress;
  this.databasePort = databasePort;
  this.gcpProject = gcpProject;
  this.gcpPubsubTopicPrefix = gcpPubsubTopicPrefix;
  this.offsetStorageFile = offsetStorageFile;
  this.databaseHistoryFile = databaseHistoryFile;
  this.inMemoryOffsetStorage = inMemoryOffsetStorage;
  this.singleTopicMode = singleTopicMode;
  this.whitelistedTables = whitelistedTables;

  Preconditions.checkArgument(RDBMS_TO_CONNECTOR_MAP.containsKey(rdbms),
      "Unsupported DBMS %s. Only supported DBMS values are %s",
      rdbms,
      String.join(",", RDBMS_TO_CONNECTOR_MAP.keySet()));

  // Prepare Debezium's table.whitelist property by removing
  // instance name from each of the whitelisted tables specified.
  String dbzWhitelistedTables = whitelistedTables.stream()
          .map(s -> s.substring(s.indexOf(".") + 1))
          .collect(Collectors.joining(","));

  Configuration.Builder configBuilder =
      Configuration.empty()
          .withSystemProperties(Function.identity())
          .edit()
          .with(EmbeddedEngine.CONNECTOR_CLASS, RDBMS_TO_CONNECTOR_MAP.get(rdbms))
          .with(EmbeddedEngine.ENGINE_NAME, APP_NAME)
          // Database connection information.
          .with("database.hostname", this.databaseAddress)
          .with("database.port", this.databasePort)
          .with("database.user", this.userName)
          .with("database.password", this.userPassword)
          .with("database.server.name", databaseName)
          .with("decimal.handling.mode", "string")
          .with(
              HistorizedRelationalDatabaseConnectorConfig.DATABASE_HISTORY,
              MemoryDatabaseHistory.class.getName());

  if (!whitelistedTables.isEmpty()) {
    LOG.info("Whitelisting tables: {}", dbzWhitelistedTables);
    configBuilder =
        configBuilder.with(
            RelationalDatabaseConnectorConfig.TABLE_WHITELIST, dbzWhitelistedTables);
  }

  if (this.inMemoryOffsetStorage) {
    LOG.info("Setting up in memory offset storage.");
    configBuilder = configBuilder.with(EmbeddedEngine.OFFSET_STORAGE,
        "org.apache.kafka.connect.storage.MemoryOffsetBackingStore");
  } else {
    LOG.info("Setting up in File-based offset storage in {}.", this.offsetStorageFile);
    configBuilder =
        configBuilder
            .with(
                EmbeddedEngine.OFFSET_STORAGE,
                "org.apache.kafka.connect.storage.FileOffsetBackingStore")
            .with(EmbeddedEngine.OFFSET_STORAGE_FILE_FILENAME, this.offsetStorageFile)
            .with(EmbeddedEngine.OFFSET_FLUSH_INTERVAL_MS, DEFAULT_FLUSH_INTERVAL_MS)
            .with(
                HistorizedRelationalDatabaseConnectorConfig.DATABASE_HISTORY,
                FileDatabaseHistory.class.getName())
            .with("database.history.file.filename", this.databaseHistoryFile);
  }

  Iterator<String> keys = debeziumConfig.getKeys();
  while (keys.hasNext()) {
    String configKey = keys.next();
    configBuilder = configBuilder.with(configKey, debeziumConfig.getString(configKey));
  }

  config = configBuilder.build();

}
 
Example 6
Source File: DebeziumMysqlToPubSubDataSender.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
public DebeziumMysqlToPubSubDataSender(
    String mysqlDatabaseInstanceName,
    String mysqlUserName,
    String mysqlUserPassword,
    String mysqlAddress,
    Integer mysqlPort,
    String gcpProject,
    String gcpPubsubTopicPrefix,
    String offsetStorageFile,
    String databaseHistoryFile,
    Boolean inMemoryOffsetStorage,
    Boolean singleTopicMode,
    Set<String> whitelistedTables,
    org.apache.commons.configuration2.ImmutableConfiguration debeziumConfig) {

  this.mysqlUserName = mysqlUserName;
  this.mysqlUserPassword = mysqlUserPassword;
  this.mysqlAddress = mysqlAddress;
  this.mysqlPort = mysqlPort;

  this.gcpProject = gcpProject;
  this.gcpPubsubTopicPrefix = gcpPubsubTopicPrefix;
  this.offsetStorageFile = offsetStorageFile;
  this.databaseHistoryFile = databaseHistoryFile;
  this.inMemoryOffsetStorage = inMemoryOffsetStorage;

  this.singleTopicMode = singleTopicMode;

  this.whitelistedTables = whitelistedTables;

  // Prepare Debezium's table.whitelist property by removing
  // instance name from each of the whitelisted tables specified.
  String dbzWhitelistedTables = whitelistedTables.stream()
          .map(s -> s.substring(s.indexOf(".") + 1))
          .collect(Collectors.joining(","));

  Configuration.Builder configBuilder = Configuration.empty()
      .withSystemProperties(Function.identity()).edit()
      .with(EmbeddedEngine.CONNECTOR_CLASS, "io.debezium.connector.mysql.MySqlConnector")
      .with(EmbeddedEngine.ENGINE_NAME, APP_NAME)
      // Database connection information.
      .with("database.hostname", this.mysqlAddress)
      .with("database.port", this.mysqlPort)
      .with("database.user", this.mysqlUserName)
      .with("database.password", this.mysqlUserPassword)
      .with("database.server.name", mysqlDatabaseInstanceName)
      .with("decimal.handling.mode", "string")
      .with(MySqlConnectorConfig.DATABASE_HISTORY, MemoryDatabaseHistory.class.getName());

  if (!whitelistedTables.isEmpty()) {
    LOG.info("Whitelisting tables: {}", dbzWhitelistedTables);
    configBuilder = configBuilder.with(MySqlConnectorConfig.TABLE_WHITELIST, dbzWhitelistedTables);
  }

  if (this.inMemoryOffsetStorage) {
    LOG.info("Setting up in memory offset storage.");
    configBuilder = configBuilder.with(EmbeddedEngine.OFFSET_STORAGE,
        "org.apache.kafka.connect.storage.MemoryOffsetBackingStore");
  } else {
    LOG.info("Setting up in File-based offset storage in {}.", this.offsetStorageFile);
    configBuilder =
        configBuilder
            .with(
                EmbeddedEngine.OFFSET_STORAGE,
                "org.apache.kafka.connect.storage.FileOffsetBackingStore")
            .with(EmbeddedEngine.OFFSET_STORAGE_FILE_FILENAME, this.offsetStorageFile)
            .with(EmbeddedEngine.OFFSET_FLUSH_INTERVAL_MS, DEFAULT_FLUSH_INTERVAL_MS)
            .with(MySqlConnectorConfig.DATABASE_HISTORY, FileDatabaseHistory.class.getName())
            .with("database.history.file.filename", this.databaseHistoryFile);
  }

  Iterator<String> keys = debeziumConfig.getKeys();
  while (keys.hasNext()) {
    String configKey = keys.next();
    configBuilder = configBuilder.with(configKey, debeziumConfig.getString(configKey));
  }

  config = configBuilder.build();

}