1):mysql数据库新建activemq库

2):向activemq安装文件夹的lib包下导入连接mysql所需要的jar包

activemq设置持久化消息mysql保存

3)修改activemq安装文件夹下的config/activemq.xml文件

3.1)在</broker>标签下新增mysql连接配置bean,如下:

    <bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
        <property name="username" value="root"/>
        <property name="password" value="root"/>
        <property name="poolPreparedStatements" value="true"/>
    </bean>

activemq设置持久化消息mysql保存

3.2)注释掉<persistenceAdapter>和<transportConnectors>这两个标签

activemq设置持久化消息mysql保存

activemq设置持久化消息mysql保存

3.3)在<broker>标签内新增如下配置

        <persistenceAdapter>
            <jdbcPersistenceAdapter dataDirectory="${activemq.data}/activemq-data" dataSource="#mysql-ds"/>
        </persistenceAdapter>

        <transportConnectors>
            <transportConnector name="default" uri="tcp://localhost:61616"/>
        </transportConnectors>

4):重启activemq

可以看在1)上建的activemq数据库多了三种activemq自生成的表

activemq设置持久化消息mysql保存

持久化mysql数据库的3张表:

activemq_acks:ActiveMQ的签收信息。

activemq_lock:ActiveMQ的锁信息。

activemq_msgs:ActiveMQ的消息的信息

5)topic模式发布者发送一条消息,订阅者此时不启动。

可以看到消息的信息表中多一条刚刚发送的消息,被持久化到了mysql数据库中

activemq设置持久化消息mysql保存

 

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-08-29
  • 2021-09-03
  • 2021-11-21
  • 2021-08-21
猜你喜欢
  • 2021-07-16
  • 2021-09-19
  • 2021-07-11
  • 2021-08-07
  • 2021-06-13
相关资源
相似解决方案