说明
之前我们使用的是RabbitMQ与Stream的结合完成消息驱动模块,这次使用Kafka与Stream。
目标
本文的目的在于结合Kafka与Stream来处理消息通信,采取自定义编写Sink(input)和Source(output)来设置多通道消息和消费组、消费分区等操作实现基本的消息驱动的微服务架构。
快速开始
环境:服务器端java 1.8、kafka 0.10.1.1、zookeeper 3.4.8(kafka内置);编程环境java 1.8、SpringBoot 1.5.2.RELEASE、SpringCloud Dalston.SR2。更换版本后注意服务器端kafka版本与SpringCloud使用的kafka版本一致
1 修改服务器端kafka配置文件
1)安装kafka与kafka-manager -> kafka与kafka-manager的安装使用
2)切换到安装目录,修改server.properties配置文件:
cd /***/kafka_2.10-0.10.1.1/
vim config/server.properties
修改如下
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# see kafka.server.KafkaConfig for additional details and defaults
############################# Server Basics #############################
# The id