简单聊一聊spring cloud stream和kafka的那点事

本文介绍了spring cloud stream如何与kafka结合使用,包括kafka的特性、kafka-manager的配置与使用,以及如何在spring cloud stream中发布和消费消息。详细讲述了从设置环境到实现消息传递的全过程。
摘要由CSDN通过智能技术生成

Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems.

The framework provides a flexible programming model built on already established and familiar Spring idioms and best practices, including support for persistent pub/sub semantics, consumer groups, and stateful partitions.

野生翻译:spring cloud stream是打算统一消息中间件后宫的男人,他身手灵活,身后有靠山spring,会使十八般武器(消息订阅模式啦,消费者组,stateful partitions什么的),目前后宫有东宫娘娘kafka和西宫娘娘rabbitMQ。

八卦党:今天我们扒一扒spring cloud stream和kafka的关系,rabbitMQ就让她在冷宫里面呆着吧。

1、先出场的正宫娘娘:kafka

Apache Kafka® is a distributed streaming platform. What exactly does that mean?

A streaming platform has three key capabilities:

  • Publish and subscribe to streams of records, similar to a message queue or enterprise messaging system.
  • Store streams of records in a fault-tolerant durable way.
  • Process streams of records as they occur.

野生翻译:老娘是个流处理平台,能干的活可多了:

  • 能处理发布/订阅消息
  • 用很稳的方式保存消息
  • 一来就处理,真的很快

总结一句话,就是快、稳、准。

kafka的运行非常简单,从这里下载,然后先运行zookeeper。在最新的kafka的下载包里面也包含了一个zookeeper,可以直接用里面的。zookeeper启动后,需要在kafka的配置文件里面配置好zookeeper的ip和端口,配置文件是config/server.properties。

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=localhost:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000

然后运行bin目录下的命令,启动kafka就可以啦

bin/kafka-server-start.sh -daemon config/server.properties

2、kafka的贴身总管,kafka-manager

kafka虽然启动了,但我们需要了解她的话,还是需要一个总管来汇报情况,我这边用的就是kafka-manager,下载地址在这里。很可惜的是只有源代码的下载,没有可运行版本的,需要自行编译,这个编译速度还挺慢的,我这边提供一个编译好的版本给大家,点这里

kafka-manager同样需要配置一下和kafka的关系,在conf/application.conf文件里面,不过配置的不是kafka自己,而是kafka挂载的zookeeper。

kafka-manager.zkhosts="localhost:2181"

然后启动bin/kafka-manager就可以了(windows环境下也有kafka-manager.bat可以运行)

这里有个坑,在windows下面运行的话,可能启动失败,提示输入行太长

这个是因为目录

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值