Spring Boot - start ActiveMQ Web Console on startu

2020-06-24 01:52发布

I have a Spring Boot app that automatically starts up an ActiveMQ broker (vm://localhost): it works, I can successfully send and receive messages.

I would like Spring Boot to also start the ActiveMQ Web Console e.g. http://localhost:8161/admin (much like it can with the H2 Database console).

Question: how do I make a Spring Boot app start the ActiveMQ Web Console?

Bonus Points: for a specific Spring @profile only?

thanks in advance

Note: I have already reviewed How to enable web console on ActiveMq embedded broker but this requires the use the hawtio which I do not want to/cannot use.

1条回答
干净又极端
2楼-- · 2020-06-24 02:36

The Web Console is a web app that can be downloaded and started in any servlet container such as Tomcat.

Here are some steps.

Enable ActiveMQ for JMX use in activemq.xml. That is - enable it in the broker tag: <broker useJmx="true" .. and

And make sure createConnector is true.

<managementContext>
        <managementContext createConnector="true"/>
</managementContext>

Download the .war from Maven. Better use the same version as the broker.

http://repo1.maven.org/maven2/org/apache/activemq/activemq-web-console/5.14.5/

Then setup the following JVM properties (JAVA_OPTS). Note that URL and ports may differ if you have changed them.

-Dwebconsole.type=properties 
-Dwebconsole.jms.url=tcp://localhost:61616 
-Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi

If you have no Tomcat (or servlet container) and prefer to run your Spring boot apps with "java -jar .. " - you can do the same with the Web console.

Example below using this app: https://github.com/jsimone/webapp-runner

Had to add jstl jar as it wasn't bundled with webapp-runner.

java -Dwebconsole.type=properties -Dwebconsole.jms.url=tcp://localhost:61616 -Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi -cp jstl-1.2.jar:webapp-runner.jar webapp.runner.launch --port 8085 activemq-web-console-5.14.5.war 

The admin console will be hosted on localhost at port 8085. This is just a starter. You may want to add fail-over, security etc etc. YMMV

查看更多
登录 后发表回答