kafka111

##kafka config
kafka.consumer.bootstrap.servers=172.0.0.1:9092
kafka.consumer.group.id=
kafka.consumer.enable.auto.commit=true
kafka.consumer.auto.commit.interval.ms=5000
kafka.consumer.session.timeout.ms=10000
kafka.consumer.concurrency=6
kafka.consumer.topic=dfp
kafka.consumer.zookeeper.connect=172.0.0.1:2181
kafka.consumer.zookeeper.timeout=5000
kafka.consumer.zookeeper.sync.time.ms=200
kafka.consumer.auto.offset.reset=smallest
kafka.consumer.serializer.class=kafka.serializer.StringEncoder
kafka.consumer.reconnect.num=3
kafka.consumer.reconnect.time=600000
kafka.corePoolSize=50
kafka.maxPoolSize=100
kafka.queueCapacity=200





<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"
    default-autowire="byName">
        <bean id="kfkListenerImpl" class="cn.com..plugin.impl.kafka.listener.KafkaListenerImpl"/>

        <bean id="messageConsumer" class="cn.com..plugin.impl.kafka.listener.MessageConsumer">
            <property name="messageListener" ref="kfkListenerImpl"/>
            <property name="executorService" ref="kfkExecutor"/>
        </bean>

        <bean id="messageListenerContainer" class="cn.com..plugin.impl.kafka.listener.MessageConsumerContainer">
            <constructor-arg ref="messageConsumer" />
        </bean>

        <bean id="kfkExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean">
            <property name="corePoolSize" value="$[kafka.corePoolSize]"/>
            <property name="maxPoolSize" value="$[kafka.maxPoolSize]"/>
            <property name="queueCapacity" value="$[kafka.queueCapacity]"/>
            <property name="threadNamePrefix" value="pool-kafka-"/>
        </bean>
    </beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Spring Boot中集成Kafka,你需要进行以下步骤: 1. 在pom.xml文件中添加Kafka依赖: ```xml <dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring-kafka</artifactId> <version>2.2.7.RELEASE</version> </dependency> ``` 2. 在application.yml文件中配置Kafka连接信息: ```yml spring.kafka.bootstrap-servers=localhost:9092 spring.kafka.consumer.group-id=my-group spring.kafka.consumer.auto-offset-reset=earliest ``` 3. 创建一个Kafka生产者: ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.stereotype.Component; @Component public class KafkaProducer { private final KafkaTemplate<String, String> kafkaTemplate; @Autowired public KafkaProducer(KafkaTemplate<String, String> kafkaTemplate) { this.kafkaTemplate = kafkaTemplate; } public void sendMessage(String topic, String message) { kafkaTemplate.send(topic, message); } } ``` 4. 创建一个Kafka消费者: ```java import org.apache.kafka.clients.consumer.ConsumerRecord; import org.springframework.kafka.annotation.KafkaListener; import org.springframework.stereotype.Component; @Component public class KafkaConsumer { @KafkaListener(topics = "my-topic", groupId = "my-group") public void listen(ConsumerRecord<String, String> record) { System.out.println("Received message: " + record.value()); } } ``` 5. 发送消息: ```java @Autowired private KafkaProducer kafkaProducer; ... kafkaProducer.sendMessage("my-topic", "Hello, Kafka!"); ``` 6. 运行应用程序并查看控制台输出,你应该能够看到消费者打印出发送的消息。 这就是在Spring Boot中集成Kafka的基本步骤。你可以根据需要进行更多的配置和自定义,例如设置监听器容器工厂和序列化器等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值