前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >docker 部署 kafka zookeeper

docker 部署 kafka zookeeper

作者头像
用户9347382
发布2022-01-10 16:46:08
发布2022-01-10 16:46:08
48700
代码可运行
举报
文章被收录于专栏:程序员阿杰程序员阿杰
运行总次数:0
代码可运行

kafka消息中间件

为了使用异步的功能,为项目引入kafka组件,提供高可用的mq服务 本次使用单点的方式为例子,集群同理

代码语言:javascript
代码运行次数:0
复制
运行zookeeper容器
docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper

运行kafka容器
docker run -d --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=ip:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://ip:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 
-v /opt/kafka/config
wurstmeister/kafka

之后修改挂载的server.properties 以及 consumer.properties

代码语言:javascript
代码运行次数:0
复制
# 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 org.apache.kafka.clients.consumer.ConsumerConfig for more details

# list of brokers used for bootstrapping knowledge about the rest of the cluster
# format: host1:port1,host2:port2 ...
bootstrap.servers=121.4.112.75:9092

# consumer group id
group.id=miniprogram-group

# What to do when there is no initial offset in Kafka or if the current
# offset does not exist any more on the server: latest, earliest, none
#auto.offset.reset=

重启容器 开放防火墙

代码语言:javascript
代码运行次数:0
复制
docker restart kafka 

添加pom依赖

代码语言:javascript
代码运行次数:0
复制
<dependency>
            <groupId>cn.org.faster</groupId>
            <artifactId>spring-boot-starter-kafka</artifactId>
            <version>1.4.2.RELEASE</version>
        </dependency>

application.yml 添加 kafka配置:

代码语言:javascript
代码运行次数:0
复制
spring
    consumer:
      group-id: miniprogram-group
      enable-auto-commit: true
      auto-commit-interval: 3000
    bootstrap-servers: ip:9092

本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名,转载请标明出处 最后编辑时间为: 2021/10/04 13:10

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-10-042,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档