SpringBoot整合activemq,activemq持久化mysql

一.ActiveMQ的安装启动

下载路径:http://archive.apache.org/dist/activemq

下载文件 apache-activemq-5.16.3-bin.tar.gz 后解压进入bin目录

启动activemq:./activemq start
停止activemq:./activemq stop
查看activemq状态:./activemq status

二.springboot整合ActiveMq

这里就不详细介绍了,感兴趣的可以看https://blog.csdn.net/xibei19921101/article/details/106669158/ 这里面有源码

三、activemq修改端口

tips:8161是后台管理系统,61616是给java用的tcp端口。

1、修改TCP 61616端口:

cd /apps/svr/activemq/conf
cat activemq.xml |grep transportConnector
        <transportConnectors>
            <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>

transportConnector name=“openwire” uri="tcp://0.0.0.0:61616 中61616修改成所需要的即可

2、修改管理页面的8161端口:

vi /apps/svr/activemq/conf/jetty.xml 
107     <bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
108              <!-- the default port number for the web console -->
109         <property name="host" value="0.0.0.0"/>
110         <property name="port" value="8161"/>
111     </bean>

host表示是否远程连接,不需要远程改为127.0.0.1即可

四、activemq配置文件持久化修改

进入解压之后的activemq的conf文件

cd /data/activemq/apache-activemq-5.16.3/conf

打开activemq.xml文件并进行编辑
<kahaDB directory="${activemq.data}/kahadb"/>注释之后加入<jdbcPersistenceAdapter dataSource="#mysql-mq" createTablesOnStartup="true" />

   <persistenceAdapter>
	<!--<kahaDB directory="${activemq.data}/kahadb"/>-->
	<jdbcPersistenceAdapter dataSource="#mysql-mq" createTablesOnStartup="true" />
</persistenceAdapter>

在下面标签之间添加mysql的配置

</broker> 	
	需要添加的mysql配置
    <import resource="jetty.xml"/> 
</beans>

<bean id="mysql-mq" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
	<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
		<!--如果是mysql8.0的版本就写这个jdbc的url路径-->
	<property name="url" value="jdbc:mysql://localhost:3306/activemq?useSSL=false&amp;serverTimezone=UTC" />
	<property name="username" value="activemq"/>
	<property name="password" value="activemq!#!"/>
	<property name="initialSize" value="5"/>
	<property name="maxTotal" value="100"/>
	<property name="maxIdle" value="30"/>
	<property name="maxWaitMillis" value="10000"/>
	<property name="minIdle" value="1"/>
</bean>

进入到lib文件夹下

cd /data/activemq/apache-activemq-5.16.3/lib
mysql-connector-java-8.0.26.jar

将对应mysql的jar包下载添加到lib文件夹下,我这里数据库是8.0+的数据库,所以用的是8.0.26的jar包,若不引入此jar包,则启动报错


版权声明:本文为weixin_41791276原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。