系统版本:
Redhat 6.8
ActiveMQ版本:
5.14.5
报错信息:
2023-05-22 16:19:00,271 | WARN | Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Invocation of init method failed; nested exception is java.net.URISyntaxException: Illegal character in hostname at index 13: ws://redhat6.8:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
Illegal character in hostname at index 13: ws://redhat6.8
从上面的报错信息,第13个字符刚好就是主机名里面包含的那个点“."。
问题原因:
目前根据网上查询的资料(连接符-、下划线_,在ActiveMQ的主机名校验中都是非法的),以及错误信息来判断,最大的可能是系统使用的主机名redhat6.8不符合ActiveMQ,也就是ActiveMQ 5.14.5版本不允许主机名存在点"."这种特殊字符存在,当然这个目前还没有查询到相关的说明文档(后续如果查询到,会及时补充完善)
解决方法:
将ActiveMQ的配置文件activemq.xml里面的0.0.0.0配置修改为127.0.0.1或者localhost即可解决,实测ActiveMQ即可成功启动。因为是生产环境,不能随意重启系统,而Redhat 6.8系统修改主机名需要重启系统(坑爹!Redhat 7.x+就不需要重启)。
注意:如果存在跨主机调用ActiveMQ的,建议还是修改主机名,如果配置修改为localhost或者127.0.0.1本地回环地址(即私网地址),会导致跨服务器无法调用。我这边调用ActiveMQ的客户端和ActiveMQ部署在同一台服务器,所以可以做如下修改。
修改前:
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
修改后:
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://127.0.0.1:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://127.0.0.1:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://127.0.0.1:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://127.0.0.1:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://127.0.0.1:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
附:
Redhat / CentOS 7.x+修改静态主机名的命令:
hostnamectl set-hostname --static vm-fdgbj1337