报错信息
org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to [马赛克 我的服务器内网IP地址]:10911 failed
at org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:390) ~[rocketmq-remoting-4.7.0.jar:4.7.0]
at org.apache.rocketmq.client.impl.MQClientAPIImpl.sendMessageSync(MQClientAPIImpl.java:503) ~[rocketmq-client-4.7.0.jar:4.7.0]
at org.apache.rocketmq.client.impl.MQClientAPIImpl.sendMessage(MQClientAPIImpl.java:487) ~[rocketmq-client-4.7.0.jar:4.7.0]
at org.apache.rocketmq.client.impl.MQClientAPIImpl.sendMessage(MQClientAPIImpl.java:431) ~[rocketmq-client-4.7.0.jar:4.7.0]
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendKernelImpl(DefaultMQProducerImpl.java:853) ~[rocketmq-client-4.7.0.jar:4.7.0]
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:583) ~[rocketmq-client-4.7.0.jar:4.7.0]
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1342) ~[rocketmq-client-4.7.0.jar:4.7.0]
at org.apache.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:343) ~[rocketmq-client-4.7.0.jar:4.7.0]
at com.janeroad.service.impl.LbInstanceServiceImpl.sendMessage(LbInstanceServiceImpl.java:142) ~[classes/:na]
at com.janeroad.service.impl.LbInstanceServiceImpl$$FastClassBySpringCGLIB$$47812268.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687) ~[spring-aop-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at com.janeroad.service.impl.LbInstanceServiceImpl$$EnhancerBySpringCGLIB$$69003a27.sendMessage(<generated>) ~[classes/:na]
at com.janeroad.controller.LbInstanceController.sendMessage(LbInstanceController.java:45) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_281]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_281]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_281]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_281]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.35.jar:9.0.35]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.6.RELEASE.jar:5.2.6.RELEASE]
排查结果
经过搜索资料我排查出这是由于跨域造成的:
解决方案
修改服务器中broker的配置,添加服务器公网IP即可
vim /usr/local/rocketmq/conf/broker.conf
新增末尾两行,xxxx代表服务器公网IP
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
namesrvAddr=xxxx:9876 #新增
brokerIP1=xxxx #新增
然后先杀死namesrv和broker进程
# cd /usr/local/rocketmq/bin
# ./mqshutdown broker
# ./mqshutdown namesrv
然后重启namesrv和broker进程,重点是重启broker的命令不同,这是为了带上刚刚修改的配置文件
# nohup ./mqnamesrv &
# nohup ./mqbroker -n localhost:9876 -c conf/broker.conf &
然后即可正常发送消息到mq了
问题描述
使用Spring Cloud Alibaba微服务架构,服务发现和配置中心使用nacos
一开始使用本地启动Nacos运行项目一切正常,
Nacos迁移到云端之后,改掉配置文件中的Nacos地址
网关的服务就报错java.net.ConnectException: no available server
,原因是它一直连接localhost:8848
。
控制台输出如下截图:
原因定位
因为父pom依赖引入:
spring-cloud-starter-alibaba-nacos-config
和spring-cloud-starter-alibaba-nacos-discovery
在本地开发中测试方便配注册发现等项目配置都配置在application.yml
,没有创建中心配置文件 bootstrap.properties
SpringBoot自动化配置默认是localhost:8848
,所以本地环境没有问题。
解决方法
去除没用的依赖(如果没使用nacos-config 删除spring-cloud-starter-alibaba-nacos-config 依赖 )
原文始发于微信公众号(0error):RocketMQ跨域问题和远程Nacos的问题
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/21940.html