我在公司网络中,并且在我们的项目中使用ActiveMQ。我试图将数据而不是默认的KahaDB持久存储在MySQL上,并遵循ActiveMQ主页上的指南
连接属性如下所示:
<bean id="mysql-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1:3306/activemq"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
当我通过bin / win64 / wrapper.exe启动活动的mq服务器时,收到“通讯链接失败”消息:
2020-09-21 14:56:36,983 | WARN | Could not get JDBC connection: Cannot create PoolableConnectionFactory (Communications link failure
The last packet successfully received from the server was 523 milliseconds ago. The last packet sent successfully to the server was 515 milliseconds ago.) | org.apache.activemq.store.jdbc.JDBCPersistenceAdapter | WrapperSimpleAppMain
java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet successfully received from the server was 523 milliseconds ago. The last packet sent successfully to the server was 515 milliseconds ago.)
at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:669)
at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:544)
at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:753)
...
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
...
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.mysql.jdbc.ExportControlled.transformSocketToSSLSocket(ExportControlled.java:187)
我注意到由于有发送和接收的数据包,仍然存在一些“连接”。但是,activemq服务器无法启动。
但是,当我将连接属性更改为登台服务器的IP地址时,activemq成功启动。
我创建了一个代码段,尝试使用相同的连接属性连接到本地数据库,并且不会引发错误:
public class ConnectionTest {
public static void main(String[] args) throws SQLException {
try (
BasicDataSource dataSource = new BasicDataSource()) {
dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/activemq");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUsername("activemq");
dataSource.setPassword("");
dataSource.setPoolPreparedStatements(true);
Connection conn = dataSource.getConnection();
conn.close();
}
}
}
在我的代码段中,我正在使用mysql-connector-java.5.1.49.jar和common-dbcp2-2.7.0.jar。这2个jar也位于activemq / lib / optional中
我尝试使用127.0.0.1,localhost和PC的IP地址。没有工作
我还可以尝试其他哪些解决方案来使主动MQ使用本地数据库?谢谢 :)
感谢@Kevin Boone指出SSL问题。我在my.ini文件中添加了以下内容:
ssl=0
然后重启mysql服务。现在,我的activeMQ代理可以连接到本地数据库。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句