首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Cloud Stream functionRouter输出尝试绑定Kafka主题

Spring Cloud Stream functionRouter输出尝试绑定Kafka主题
EN

Stack Overflow用户
提问于 2021-05-06 22:08:21
回答 1查看 328关注 0票数 1

我正在尝试迁移到Spring Cloud Stream的新的函数式编程模型,取代下面这样的条件StreamListener注释

代码语言:javascript
复制
@StreamListener("app-input", condition = "headers['eventName']=='Funded'")

使用类似于

代码语言:javascript
复制
@Bean
fun router() = MessageRoutingCallback {
    when (it.headers["eventName"]) {
        "Funded" -> "funded"
        else -> "ignored"
    }
}
@Bean
fun funded() = Consumer { message: Message<Funded> ->
    ...
}

@Bean
fun ignored() = Consumer { message: Message<*> ->
    ...
}

具有将频道链接到主题的关联属性

代码语言:javascript
复制
spring.cloud.function.definition=functionRouter
spring.cloud.stream.bindings.functionRouter-in-0.destination=MyTopic

我需要这种间接性,因为有多种Avro消息类型都到达MyTopic,需要进行反序列化和不同的路由

这一切都很顺利,我可以按预期消费和路由消息。然而,以这种方式使用functionRouter有一个意想不到的副作用,即当没有可用的主题时,它也会尝试将functionRouter-out-0绑定到Kafka,因此应用程序每隔30秒尝试附加到代理上名为"functionRouter-out-0“的主题,正如您所预期的那样,它会因授权错误而失败。

代码语言:javascript
复制
2021-05-06 12:57:55.654 WARN  [screening]                            o.s.c.s.b.k.p.KafkaTopicProvisioner      : No partitions have been retrieved for the topic (functionRouter-out-0). This will affect the health check.
2021-05-06 12:57:56.198 WARN  [screening]                            org.apache.kafka.clients.NetworkClient   : [Producer clientId=producer-3] Error while fetching metadata with correlation id 4 : {functionRouter-out-0=TOPIC_AUTHORIZATION_FAILED}
2021-05-06 12:57:56.199 ERROR [screening]                            org.apache.kafka.clients.Metadata        : [Producer clientId=producer-3] Topic authorization failed for topics [functionRouter-out-0]
2021-05-06 12:57:56.199 ERROR [screening]                            o.s.c.s.b.k.p.KafkaTopicProvisioner      : Failed to obtain partition information
org.apache.kafka.common.errors.TopicAuthorizationException: Not authorized to access topics: [functionRouter-out-0]

因此,问题要么是a)我如何停止函数either out-0通道尝试绑定到Kafka,或者b)我如何在不需要中间通道的情况下实现这一点?

Spring Cloud Stream event routing functionality autocreates new topic也是类似的,但是从来没有收到过回复。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-06 22:47:45

我相信这是个bug。我打开了一个问题,如果你想关注它:

https://github.com/spring-cloud/spring-cloud-stream/issues/2168

作为一种变通方法,只需将其指向相同的目的地

代码语言:javascript
复制
spring.cloud.function.definition=functionRouter
spring.cloud.stream.bindings.functionRouter-in-0.destination=so67419839
spring.cloud.stream.bindings.functionRouter-out-0.destination=so67419839
spring.cloud.stream.bindings.functionRouter-in-0.group=so67419839

因为委托都是Consumer的,所以我们不会实际发送任何东西。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67419839

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档