简体   繁体   English

如何根据条件向2个kafka主题发布消息 - spring cloud stream

[英]How to publish message to 2 kafka topics based on condition - spring cloud stream

Currently i have a spring clound funtion which consumes a topic and publish in to another topic.目前我有一个 spring clound 函数,它使用一个主题并发布到另一个主题。 But for particular condition i need to publish message to another topic.但对于特定情况,我需要将消息发布到另一个主题。 Basically need to publish message to multiple topic from spring cloud function.基本上需要从 spring 云 function 向多个主题发布消息。

Current code snippets当前代码片段

@Bean
public Function<Message<InputMessage>, Message<OutputMessage>>
    messageTransformer(){
    return new KafkaTransformer();
    }


public class KafkaTransformer
    implements Function<
    Message<InputMessage>, Message<OutputMessage>> {

  @Override
  public Message<OutputMessage> apply(
      Message<InputMessage> inputMessage) {
    try {
      Message<OutputMessage> outputMessage = process(inputMessage);
      return outputMessage;
    } catch (Exception e) {
      // need to send message to another topic ( which is other than dlq).
    }
  }
}

spring.cloud.stream.bindings.messageTransformer-in-0.destination=input.topic
spring.cloud.stream.bindings.messageTransformer-out-0.destination=output.topic
spring.cloud.function.definition=messageTransformer

Did you look into using StreamBridge API for this?您是否考虑过为此使用StreamBridge API? Sounds like that should work for what you are looking for.听起来应该可以满足您的需求。 Here are the docs .这是文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Cloud Stream向Kafka主题发送数据失败 - Spring Cloud Stream Sending Data to Kafka Topics Fails 如何在应用程序启动时使用Spring Cloud Stream发布消息? - How to publish a message with Spring Cloud Stream on application Startup? 在 Kafka 代理本身或通过 Spring Cloud Stream 配置主题 - Configure Topics in Kafka broker itself or via Spring Cloud Stream 如何解决 Spring Cloud Stream Kafka Streams Binder 中多路复用输入主题的 InvalidTopicException? - How to solve InvalidTopicException with multiplexed input topics in Spring Cloud Stream Kafka Streams Binder? 如何使用 spring 云 stream binder kafka 流依赖项使用协议缓冲区(protobuf)来使用来自 kafka 主题的消息? - How to consume messages from kafka topics using protocol buffers (protobuf) by spring cloud stream binder kafka streams dependency? 实现 Spring 服务,根据配置向不同的 Kafka 主题发送消息 - Implement Spring Service to send message to different Kafka topics based on configuration 默认情况下如何使用Kafka Spring Cloud Stream并使用汇合API生成的Kafka消息? - How to consume from Kafka Spring Cloud Stream by default and also consume a Kafka message generated by the confluent API? 如何使用 kafka 流加入主题 - How to join topics with kafka stream Spring-cloud-stream无法产生kafka消息 - Spring-cloud-stream cannot produce kafka message Spring 云 stream:Kafka Sink 收到备用消息 - Spring Cloud stream: Kafka Sink gets alternate message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM