【问题标题】:Active MQ - able to connect to other machine MySQL but not local machine MySQLActive MQ - 能够连接到其他机器 MySQL 但不能连接到本地机器 MySQL
【发布时间】:2020-09-21 17:01:21
【问题描述】:

我在公司网络中,并在我们的项目中使用 ActiveMQ。我正在尝试将数据保存在 MySQL 而不是默认的 KahaDB 上,并按照ActiveMQ home page的指南进行操作

连接属性如下所示:

    <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 成功启动。

我创建了一个 sn-p 来尝试使用相同的连接属性连接到本地数据库,并且没有抛出错误:

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();
        }
    }
}

在我的 sn-p 中,我使用的是 mysql-connector-java.5.1.49.jarcommon-dbcp2-2.7.0.jar。这2个jar也在activemq/lib/optional中

我尝试了 127.0.0.1、localhost 和我的 PC 的 IP 地址。没有工作

我可以尝试什么其他解决方案让活动 mq 使用我的本地数据库? 谢谢:)

【问题讨论】:

  • 我不是 MySQL 方面的专家,但看起来好像异常是由于 SSL 握手失败而导致的。您希望 MySQL 服务器使用 SSL 吗?如果是这样,您是否将数据库中的相关 SSL 证书导入代理?如果问题 SSL 相关,那么使用-Djavax.net.debug=ssl 运行代理可能会揭示出问题所在。但是您希望通信被加密吗?如果你不这样做,也许 MySQL 上有一些配置需要更改?
  • @KevinBoone 非常感谢您!我在本地 MySQL 上禁用了 SSL,并且活动 MQ 代理成功启动!

标签: java mysql activemq


【解决方案1】:

感谢@Kevin Boone 指出 SSL 的问题。我在 my.ini 文件中添加了以下内容:

ssl=0

然后重启mysql服务。现在我的 activeMQ 代理可以连接到本地数据库了。

【讨论】:

    猜你喜欢
    • 2022-07-21
    • 1970-01-01
    • 2018-04-24
    • 2019-05-10
    • 2012-08-15
    • 1970-01-01
    • 2013-04-21
    • 2017-10-05
    • 1970-01-01
    相关资源
    最近更新 更多