找回密码
 会员注册
查看: 39|回复: 0

RocketMQ连接报错RemotingConnectExceptionconnectto<192.168.57.1299876>解决

[复制链接]

6

主题

0

回帖

19

积分

新手上路

积分
19
发表于 2024-9-10 09:12:07 | 显示全部楼层 |阅读模式
文章目录前言一、RocketMQ连接报错处理1.1报错信息1.2修改broker.conf文件1.3Linux开放端口1.4项目启动成功前言上一篇文章:基于SpringBoot整合RocketMQ异步发送短信功能在项目启动的过程中报了RocketMQ连接错误。针对这个问题,本文给予记录。一、RocketMQ连接报错处理1.1报错信息ErrorstartingApplicationContext.Todisplaytheconditionsreportre-runyourapplicationwith'debug'enabled.2023-12-2421:12:22.374ERROR26188---[restartedMain]o.s.boot.SpringApplication:Applicationrunfailedjava.lang.RuntimeException:java.lang.IllegalStateExceptionrg.apache.rocketmq.remoting.exception.RemotingConnectException:connectto[192.168.57.129:9876]failed atorg.apache.rocketmq.spring.autoconfigure.ListenerContainerConfiguration.registerContainer(ListenerContainerConfiguration.java:123)~[rocketmq-spring-boot-2.2.2.jar:2.2.2] atjava.util.HashMap.forEach(HashMap.java:1289)~[na:1.8.0_181] atorg.apache.rocketmq.spring.autoconfigure.ListenerContainerConfiguration.afterSingletonsInstantiated(ListenerContainerConfiguration.java:79)~[rocketmq-spring-boot-2.2.2.jar:2.2.2] atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:963)~[spring-beans-5.3.6.jar:5.3.6] atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)~[spring-context-5.3.6.jar:5.3.6] atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)~[spring-context-5.3.6.jar:5.3.6] atorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144)~[spring-boot-2.4.5.jar:2.4.5] atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:782)[spring-boot-2.4.5.jar:2.4.5] atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:774)[spring-boot-2.4.5.jar:2.4.5] atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)[spring-boot-2.4.5.jar:2.4.5] atorg.springframework.boot.SpringApplication.run(SpringApplication.java:339)[spring-boot-2.4.5.jar:2.4.5] atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1340)[spring-boot-2.4.5.jar:2.4.5] atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1329)[spring-boot-2.4.5.jar:2.4.5] atcom.huang.quickstart.QuickStartApplication.main(QuickStartApplication.java:12)[classes/:na] atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)~[na:1.8.0_181] atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)~[na:1.8.0_181] atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)~[na:1.8.0_181] atjava.lang.reflect.Method.invoke(Method.java:498)~[na:1.8.0_181] atorg.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[spring-boot-devtools-2.4.5.jar:2.4.5]1234567891011121314151617181920212223简单的理解就是RocketMQ连接不上虚拟机地址192.168.57.129:9876信息。1.2修改broker.conf文件进入broker.conf目录下cd/mydata/rocketmq/rocketmq-4.9.1/conf1vimbroker.conf1加入两行(建议直接复制,然后再修改为自己的IP),一定是大写IP。namesrvAddr=192.168.57.129:9876brokerIP1=192.168.57.12912然后重启nameserver和broker(一定要先启动namesrv,因为消息服务器是注册到命名服务器上的)。nohupshmqnamesrv1再启动消息服务器,同时指定刚刚修改过的conf文件,不然还是会读取原本默认的阿里外网IP,还是会报错。nohupshmqbroker-n192.168.57.129:9876-c../conf/broker.conf1备注:-n指定的是注册到哪个消息服务器上-c指定的是刚刚修改的conf配置文件查看日志信息namesrv和broker启动成功[root@localhostbin]#catnohup.outJavaHotSpot(TM)64-BitServerVMwarning:UsingtheDefNewyoungcollectorwiththeCMScollectorisdeprecatedandwilllikelyberemovedinafuturereleaseJavaHotSpot(TM)64-BitServerVMwarning:UseCMSCompactAtFullCollectionisdeprecatedandwilllikelyberemovedinafuturerelease.TheNameServerbootsuccess.serializeType=JSONThebroker[broker-a,192.168.57.129:10911]bootsuccess.serializeType=JSONandnameserveris192.168.57.129:987612345重新启动SpringBoot项目,发现还是报错!!!1.3Linux开放端口排查了一下原因:发现可能是Linux中RocketMQ的9876端口没有开放的问题!!!1、开启防火墙systemctlstartfirewalld12、开放指定端口firewall-cmd--zone=public--add-port=9876/tcp--permanent1备注:–zone作用域–add-port=9876/tcp添加端口,格式为:端口/通讯协议–permanent永久生效,没有此参数重启后失效3、重启防火墙firewall-cmd--reload14、查看端口号netstat-ntlp#查看当前所有tcp端口netstat-ntulp|grep9876#查看所有9876端口使用情况1.4项目启动成功1、开放端口以及重启防火墙[root@localhostbin]#firewall-cmd--zone=public--add-port=9876/tcp--permanentsuccess[root@localhostbin]#firewall-cmd--reloadsuccess12342、重启启动SpringBoot项目2023-12-2421:38:39.978INFO24612---[restartedMain]a.r.s.s.DefaultRocketMQListenerContainer:runningcontainerefaultRocketMQListenerContainer{consumerGroup='screening-record-consumer_status-change',namespace='',nameServer='192.168.57.129:9876',topic='screening-record-topic',consumeMode=CONCURRENTLY,selectorType=TAG,selectorExpression='status-change',messageModel=CLUSTERING',tlsEnable=false}2023-12-2421:38:39.978INFO24612---[restartedMain]o.a.r.s.a.ListenerContainerConfiguration:Registerthelistenertocontainer,listenerBeanName:screeningRecordStatusChangeConsumer,containerBeanNamerg.apache.rocketmq.spring.support.DefaultRocketMQListenerContainer_22023-12-2421:38:40.039INFO24612---[restartedMain]o.s.b.w.embedded.tomcat.TomcatWebServer:Tomcatstartedonport(s):9090(http)withcontextpath''2023-12-2421:38:40.053INFO24612---[restartedMain]c.h.quickstart.QuickStartApplication:StartedQuickStartApplicationin8.829seconds(JVMrunningfor10.857)12343、项目启动成功,RocketMQ连接报错问题解决!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

QQ|手机版|心飞设计-版权所有:微度网络信息技术服务中心 ( 鲁ICP备17032091号-12 )|网站地图

GMT+8, 2025-1-7 05:55 , Processed in 0.434526 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表