【问题标题】:Configuration of 'sasl.jaas.config' when you have 2 separate topics, each having separate connection key?当您有 2 个单独的主题时配置“sasl.jaas.config”,每个主题都有单独的连接密钥?
【发布时间】:2021-03-31 23:01:11
【问题描述】:

当您有 2 个单独的主题,每个主题都有单独的连接密钥时,我正在寻找有关 sasl.jaas.config 配置的说明?我正在使用spring-cloud-starter-stream-kafka 3.1 版。我没有使用spring-cloud-stream-binder-kafka,也不知道that would solve my problem是否。

当只涉及 1 个主题时,我可以找到很多示例,使用由消费者继承的“spring.cloud.stream.kafka.binder.configuration 中的通用配置进行连接。

我有一个场景,我有一个输入和输出,每个主题都有自己的单独主题,我想在 .yml 中配置它。这可以通过 .yml 配置实现吗?

我的最佳猜测是尝试配置密钥 spring.cloud.stream.bindings.input.configuration.sasl.jaas.config,但该配置似乎不存在,是吗?

这是我最好的猜测,但它不正确,因为它不起作用:

spring:
  ...
  cloud:
    stream:
      kafka:
        binder:
          brokers: ...
          defaultBrokerPort: 9093
          auto-create-topics: true
          configuration:
            security.protocol: SASL_SSL
            sasl:
              mechanism: PLAIN
        bindings:
          eeoi-sink:
            consumer:
              enableDlq: false
              dlqName: input_dlq
              ackEachRecord: true
              autoCommitOffset: false
      bindings:
        eeoi-sink:
          destination: input
          contentType: application/json
          group: $Default
          consumer:
            max-attempts: 1
          configuration:
            sasl:
              jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="...";
        acknowledgement-source:
          destination: output
          contentType: application/json
          group: $Default
          configuration:
            sasl:
              jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="...";

【问题讨论】:

    标签: java apache-kafka-streams spring-kafka spring-cloud-stream spring-cloud-stream-binder-kafka


    【解决方案1】:

    spring.cloud.stream.bindings.input.configuration.sasl.jaas.config 将不起作用。正确的属性键是spring.cloud.stream.kafka.bindings.input.consumer.configuration.sasl.jaas.config

    如果你想使用单独的 jaas 配置,你需要使用多绑定器设置。有关一些想法,请参阅此应用程序:https://github.com/spring-cloud/spring-cloud-stream-samples/blob/master/multi-binder-samples/kafka-multi-binder-jaas/src/main/resources/application.yml

    在此示例中,它提供了jaas config for the binder,您可以简单地将其替换为binder.configuration.sasl.jaas.config

    将相同的 Kafka 集群用作两个 binder 设置的代理,但 jaas 配置不同。

    但是,我认为您遇到的问题是不同的。您的jaas 配置最终被委托给java 安全配置,它为每个JVM 保留jaas 配置的静态副本。因此,在 JVM 中静态设置后提供的任何 jaas 配置都将被忽略。

    有关相关问题的更多详细信息,请参阅:https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/issues/874

    此问题提供了一些解决此问题的方法。一种是使两个主题的连接字符串、密码等相同,这样,使用相同的jaas 配置值。这可能不是一个理想的解决方案,并且首先破坏了不同凭据的目的。上述示例有效的原因是我们在两个活页夹中使用了相同的用户名/密码组合。

    另一种选择是将应用程序分成两部分。这样,每个主题的jaas 配置就驻留在不同的应用程序中。

    【讨论】:

    • 谢谢。这就是我需要的信息。我现在可以工作了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 2022-12-24
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多