简体   繁体   English

Kafka的Spring集成-配置多个主题

[英]Spring Integration for Kafka - Configuring Multiple Topics

There is a need for me to post certain messages to one topic and another set of messages to another topic, I am currently using Spring integration for Kafka to post messages to one topic, but I am looking for example about how can I post messages to different topics based on the situation. 我需要将某些消息发布到一个主题,将另一组消息发布到另一个主题,我目前正在使用Kafka的Spring集成将消息发布到一个主题,但是我正在寻找例如有关如何将消息发布到的信息。根据情况选择不同的主题。

I am using int-kafka:producer-configuration tags to create context 我正在使用int-kafka:producer-configuration标签创建上下文

Update 更新

Thank you that is working. 谢谢你的工作。 I am using the below configuration in my application context xml and the below in my code to check get the desired TOPIC name kafkaUpdate = channel.send(MessageBuilder.withPayload(jsonAuditLog).setHeader(KafkaHeaders.TOPIC, "").build(), kafkaTimeOut.longValue()); 我在应用程序上下文xml中使用以下配置,在代码中使用以下配置,以检查是否获得所需的主题名称kafkaUpdate = channel.send(MessageBuilder.withPayload(jsonAuditLog).setHeader(KafkaHeaders.TOPIC,“”).build() ,kafkaTimeOut.longValue());

Code is working and I see messages getting posted to different topics as I wanted, but not sure if this is the rite way.... 代码正在运行,我看到的消息已按需要发布到不同的主题,但是不确定这是否是仪式方式。

What you are about is very old version. 您要使用的是非常旧的版本。 The latest Spring Integration Kafka 3.0.1 is based on the Spring Kafka 2.1.2 and there is no any producer-configuration for a long time already. 最新的Spring Integration Kafka 3.0.1基于Spring Kafka 2.1.2并且很长一段时间都没有任何producer-configuration

Consider to develop your application for the actual Apache Kafka 1.0.0 . 考虑为实际的Apache Kafka 1.0.0开发应用程序。

The new <int-kafka:outbound-channel-adapter> has topic-expression for your purpose: https://docs.spring.io/spring-kafka/docs/2.1.2.RELEASE/reference/html/_spring_integration.html#si-outbound 新的<int-kafka:outbound-channel-adapter>具有topic-expression供您使用: https : //docs.spring.io/spring-kafka/docs/2.1.2.RELEASE/reference/html/_spring_integration.html #SI-出境

UPDATE UPDATE

The old version has this attribute on the <int-kafka:outbound-channel-adapter> : 旧版本在<int-kafka:outbound-channel-adapter>上具有此属性:

<xsd:attribute name="topic-expression" type="xsd:string">
                <xsd:annotation>
                    <xsd:documentation><![CDATA[
                                Specifies the expression to determine the name of the Kafka topic
                                against the Message at runtime.
                                This attribute is mutually exclusive with 'topic' attribute.
                            ]]></xsd:documentation>
                </xsd:annotation>
</xsd:attribute>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM