Activemq控制台的独立部署

Apache Activemq是一个高性能的开源消息队列。在启动它的时候,会自动启动一个自带的Web控制台,通过控制台可以查看当前Activemq服务器的情况,包括队列、主题、连接、订阅者等。这个控制台是通过嵌入式的Jetty容器启动的。
不过有时候我们可能需要独立部署Web控制台,比如在Tomcat中通过插件形式启动Activemq,此时无法通过嵌入Jetty容器的方式启动Web控制台(因为Tomcat和Jetty不兼容)。此时可以按照如下方式独立部署Web控制台。

抽取控制台代码

首先从官网下载Activemq的源代码,我下载的是5.15.5版本。之后从中拷贝出activemq-web-console子模块,作为一个独立项目。
在这里插入图片描述

从idea启动项目

可以通过intellij idea从activemq-web-console目录新建项目,注意选择maven类型项目。之后等待maven自动下载所需依赖完毕。打开pom.xml,注释掉下面的配置

<!--      <plugin>-->
<!--          <groupId>${jetty.maven.groupid}</groupId>-->
<!--        <artifactId>jetty-maven-plugin</artifactId>-->
<!--        <version>${jetty-version}</version>-->
<!--        <configuration>-->
<!--          <connectors>-->
<!--            <connector implementation="org.eclipse.jetty.server.ServerConnector">-->
<!--              <port>${jetty.port}</port>-->
<!--              <maxIdleTime>60000</maxIdleTime>-->
<!--            </connector>-->
<!--          </connectors>-->

<!--          <webAppConfig>-->
<!--            <contextPath>/</contextPath>-->
<!--          </webAppConfig>-->

<!--          <systemProperties>-->
<!--            &lt;!&ndash; enable easy connection to JConsole &ndash;&gt;-->
<!--            <systemProperty>-->
<!--              <name>com.sun.management.jmxremote</name>-->
<!--              <value />-->
<!--            </systemProperty>-->

<!--            &lt;!&ndash; Start an own broker &ndash;&gt;-->
<!--            <systemProperty>-->
<!--              <name>webconsole.type</name>-->
<!--              <value>embedded</value>-->
<!--            </systemProperty>-->
<!--            <systemProperty>-->
<!--                <name>activemq.data</name>-->
<!--                <value>${project.build.directory}/activemq-data</value>-->
<!--            </systemProperty>-->

<!--            &lt;!&ndash;-->
<!--               Use the following configuration to connect to a remote broker using JMX-->
<!--                        <systemProperty>-->
<!--                          <name>webconsole.type</name>-->
<!--                          <value>properties</value>-->
<!--                        </systemProperty>-->
<!--                        <systemProperty>-->
<!--                          <name>webconsole.jms.url</name>-->
<!--                          <value>tcp://localhost:61616</value>-->
<!--                        </systemProperty>-->
<!--                        <systemProperty>-->
<!--                          <name>webconsole.jmx.url</name>-->
<!--                          <value>service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi</value>-->
<!--                        </systemProperty>-->
<!--            &ndash;&gt;-->
<!--          </systemProperties>-->
<!--          <scanIntervalSeconds>10</scanIntervalSeconds>-->
<!--        </configuration>-->
<!--      </plugin>-->

因为我们使用Tomcat启动项目,所以不需要这个Jetty相关的插件。

配置Tomcat

配置Tomcat容器启动项,如下图所示

在这里插入图片描述

运行项目,会报一个异常,是因为缺少jstl的jar包导致,可以从maven中央仓库下载jar包,并放到Tomcat的lib目录中。再次启动之后会打开浏览器,显示如下画面

在这里插入图片描述

可见项目启动成功。可以在本地启动一个Activemq服务,并通过这个控制台查看服务的运行情况。

构建项目

通过终端进入activemq-web-console目录,执行

mvn install

中间会报一些错,但最后还是build success。
项目会构建成功,并在target目录中生成一个war包activemq-web-console-5.15.5.war。将这个war包拷贝到Tomcat的webapps中。
通过tomcat\bin\startup.sh启动Tomcat,之后再次打开网址,会看到与从idea中启动同样的页面。

总结

以上就是独立部署Activemq控制台的过程,可以用在通过Tomcat容器嵌入式启动Activemq的场景,用来监控Activemq服务的运行情况。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章