实测springboot Flume整合kafka

启动flume

在安装目录下执行

flume-ng.cmd  agent -conf ../conf  -conf-file ../conf/example.conf  -name a1  -property flume.root.logger=INFO,console

在这里插入图片描述

启动zookeeper

.\bin\windows\zookeeper-server-start.bat  .\config\zookeeper.properties

在这里插入图片描述

启动kafka

在安装目录下

.\bin\windows\kafka-server-start.bat .\config\server.properties

在这里插入图片描述

创建topic测试主题

在kafka安装路径下

.\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

创建生产者产生消息

在kafka安装路径下

.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic test

在这里插入图片描述

创建消费者接收消息

在kafka安装路径下

.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning

在这里插入图片描述

修改example.conf中的文件

 # example.conf: A single-node Flume configuration
 
 # Name the components on this agent
 a1.sources = r1
 a1.sinks = k1
 a1.channels = c1
 
 # Describe/configure the source
 a1.sources.r1.type = avro
 a1.sources.r1.bind = 192.168.0.12
 a1.sources.r1.port = 44444
 
  # Describe the sink
 a1.sinks.k1.type = logger
 
 # 配置Sink组件,将接收数据输出到对应kafka
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.bootstrap.servers = 127.0.0.1:9092
a1.sinks.k1.kafka.topic = test
a1.sinks.k1.kafka.flumeBatchSize = 20
a1.sinks.k1.kafka.producer.acks = 1
a1.sinks.k1.kafka.producer.linger.ms = 1
a1.sinks.k1.kafka.producer.compression.type = snappy
 

 
 # Use a channel which buffers events in memory
 a1.channels.c1.type = memory
 a1.channels.c1.capacity = 1000
 a1.channels.c1.transactionCapacity = 100
 
 # Bind the source and sink to the channel
 a1.sources.r1.channels = c1
 a1.sinks.k1.channel = c1

在这里插入图片描述
a1.sinks.k1.type = logger,必须在配置Sink组件上

a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
# 本地ip,端口号
a1.sinks.k1.kafka.bootstrap.servers = 127.0.0.1:9092 
#kafka主题交换机名称
a1.sinks.k1.kafka.topic = test
a1.sinks.k1.kafka.flumeBatchSize = 20
a1.sinks.k1.kafka.producer.acks = 1
a1.sinks.k1.kafka.producer.linger.ms = 1
a1.sinks.k1.kafka.producer.compression.type = snappy

springboot项目

		<dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>

发送的数据
启动springboot项目
在这里插入图片描述
在flume控制台如下结果
在这里插入图片描述

在消费者控制台
在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Flume 可以与 Kafka 进行整合,以实现高效的数据传输和处理。具体步骤如下: 1. 首先需要在 Flume 中配置 Kafka 的相关信息,包括 Kafka 的主机名、端口号、topic 等信息。 2. 在 Flume 的配置文件中,需要添加 Kafka Sink,以将数据发送到 Kafka 中。在 Sink 的配置中,需要指定 Kafka 的相关信息,以及数据的序列化方式等。 3. 启动 Flume Agent,即可将数据传输到 Kafka 中。 下面是一个示例配置文件,将 Flume 中的数据发送到 Kafka 中: ```properties # Name the components on this agent a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r1.type = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # Describe the sink a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink a1.sinks.k1.topic = test a1.sinks.k1.brokerList = localhost:9092 a1.sinks.k1.batchSize = 20 a1.sinks.k1.requiredAcks = 1 a1.sinks.k1.channel = c1 # Use a channel which buffers events in memory a1.channels.c1.type = memory a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 # Bind the source and sink to the channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 ``` 在上述配置文件中,首先定义了一个 netcat Source,用于接收数据。然后定义了一个 Kafka Sink,将数据发送到 Kafka 中。最后定义了一个 memory Channel,用于在内存中缓存事件。 启动 Flume Agent 的命令如下: ``` $ flume-ng agent -c conf -n a1 -f conf/flume_kafka.conf >/dev/null 2>&1 & ``` 其中,-c 参数指定了配置文件所在的目录,-n 参数指定了 Agent 的名称,-f 参数指定了配置文件的名称。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值