【问题标题】:Typesafe config override with colon-including variable类型安全配置覆盖带有冒号的变量
【发布时间】:2021-03-10 08:32:39
【问题描述】:

我正在使用 Typesafe Config 来管理我的 Flink SQL 命令。例如,

source = """
CREATE TABLE kafka_source (
    `body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>>
) WITH (
    'connector' = 'kafka',
    'topic' = 'data-report-stat-old-logtype7',
    'properties.bootstrap.servers' = '10.111.135.233:9092',
    'properties.group.id' = 'flink-test2',
    'json.fail-on-missing-field' = 'false',
    'format' = 'json'
)
"""

我的properties.bootstrap.servers 是特定于 maven-profile,因此我想在 Maven pom.xml 中配置它

<profiles>
    <profile>
        <id>testing</id>
        <properties>
            <kafka.source.servers>10.111.135.233:9092</kafka.source.servers>
        </properties>
    </profile>
</profiles>

我想在 Typesafe 配置中引用和使用该属性,

source = """
CREATE TABLE kafka_source (
    `body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>>
) WITH (
    'connector' = 'kafka',
    'topic' = 'data-report-stat-old-logtype7',
    'properties.bootstrap.servers' = '"""${kafka.source.servers}"""',
    'properties.group.id' = 'flink-test2',
    'json.fail-on-missing-field' = 'false',
    'format' = 'json'
)
"""

但是,如果我运行 mvn clean package -Ptesting,配置会内置

source = """
CREATE TABLE kafka_source (
    `body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>>
) WITH (
    'connector' = 'kafka',
    'topic' = 'data-report-stat-old-logtype7',
    'properties.bootstrap.servers' = '"""10.111.135.233:9092"""',
    'properties.group.id' = 'flink-test2',
    'json.fail-on-missing-field' = 'false',
    'format' = 'json'
)
"""

加载配置时会抛出异常,因为10.111.135.233:9092 包含::

Expecting close brace } or a comma, got ':' (if you intended ':' to be part of a key or string value, try enclosing the key or value in double quotes

解决这个问题的正确方法是什么?谢谢!

【问题讨论】:

    标签: maven typesafe-config


    【解决方案1】:

    我相信这是类型安全配置的问题。要解决此问题,请使用application.properties 文件而不是application.conf。

    last-n-clicks.generation-ingestion.source=\
    CREATE TABLE kafka_source ( \
    `body` ROW<`log` ROW<`uid` BIGINT, serverts BIGINT, `contentstr` STRING>> \
    ) WITH ( \
    'connector' = 'kafka', \
    'topic' = 'data-report-stat-old-logtype7', \
    'properties.bootstrap.servers' = '${kafka.source.servers}', \
    'properties.group.id' = 'flink-test2', \
    'json.fail-on-missing-field' = 'false', \
    'format' = 'json' \
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      • 2017-12-09
      • 2015-08-18
      • 2015-11-16
      • 2017-02-07
      • 2013-04-18
      • 1970-01-01
      相关资源
      最近更新 更多