英文:
Active MQ - able to connect to other machine MySQL but not local machine MySQL
问题
我在企业网络中,我们的项目中使用了 ActiveMQ。我尝试将数据持久化到 MySQL 中,而不是默认的 KahaDB,并且正在按照 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 启动 ActiveMQ 服务器时,我收到了 "通信链路失败" 的错误:
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。这两个 JAR 文件也在 activemq/lib/optional 目录中。
我尝试了 127.0.0.1、localhost 和我的计算机的 IP 地址。都没有起作用。
还有哪些解决方案可以尝试,以便让 ActiveMQ 使用我的本地数据库呢?
谢谢
英文:
I'm in a corporate network and using ActiveMQ in our project. I'm trying to persist data on MySQL instead of the default KahaDB and following the guide at ActiveMQ home page
the connection properties looks like this:
<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>
When I starts the active mq server via bin/win64/wrapper.exe, I received "Communication link failure":
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)
I noticed that there's still some 'connection' since there were packets sent and received. The activemq server couldn't start nonetheless.
When I changed the connection properties to our staging server's ip address however, activemq started successfully.
I created a snippet to try connecting to the local db using the same connection properties and no error is thrown:
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();
}
}
}
In my snippet I'm using mysql-connector-java.5.1.49.jar and common-dbcp2-2.7.0.jar. These 2 jars are also in activemq/lib/optional
I tried 127.0.0.1, localhost, and my PC's IP address. None worked
What other solution could I try to have active mq use my local database?
Thanks
答案1
得分: 0
感谢 @Kevin Boone 指出了 SSL 问题。我在 my.ini 文件中添加了以下内容:
ssl=0
然后重新启动了 MySQL 服务。现在我的 ActiveMQ 经纪人能够连接到本地数据库。
英文:
Thanks @Kevin Boone for pointing out the issue with SSL. I added in my my.ini file the following:
ssl=0
then restarted mysql service. Now my activeMQ broker could connect to the local db.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论