如何使用Hawtio在spring boot中连接到嵌入式activeMQ?

时间:2018-02-12 23:16:45

标签: spring-boot activemq stomp hawtio

我的spring boot应用程序包含嵌入式activeMQ,我想使用hawtio连接到web控制台但无法连接。 我执行以下步骤:

1-in cmd“java -jar hawtio-app-1.5.7.jar”。

2-尝试连接主机:localhost 端口:1099 路径:/ api / jolokia 但不工作返回以下内容:

无法加载资源:服务器响应状态为500(localhost:1099无法响应)

的pom.xml     

<!-- Starter for building web, including RESTful, applications using Spring 
MVC. Uses Tomcat as the default embedded container -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- the embedded container dependencies as “provided” -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

<!-- Logging libraries -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<!-- WebSocket libraries -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<!-- reactor project libraries -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-bus</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-net</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.33.Final</version>
</dependency>

<!-- Email -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-stomp</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-kahadb-store</artifactId>
<scope>runtime</scope>
</dependency>




</dependencies>

<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

以下日志启动:

`2018-02-13;00:31:26.976 [localhost-startStop-1] INFO 
                o.s.b.w.s.ServletRegistrationBean.onStartup(190) - Mapping servlet: 'dispatcherServlet' to [/]
2018-02-13;00:31:27.016 [localhost-startStop-1] INFO 
                o.s.b.w.s.FilterRegistrationBean.configure(258) - Mapping filter: 'characterEncodingFilter' to: [/*]
2018-02-13;00:31:27.019 [localhost-startStop-1] INFO 
                o.s.b.w.s.FilterRegistrationBean.configure(258) - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-02-13;00:31:27.021 [localhost-startStop-1] INFO 
                o.s.b.w.s.FilterRegistrationBean.configure(258) - Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-02-13;00:31:27.022 [localhost-startStop-1] INFO 
                o.s.b.w.s.FilterRegistrationBean.configure(258) - Mapping filter: 'requestContextFilter' to: [/*]
2018-02-13;00:31:28.938 [main] INFO 
                o.s.s.c.ThreadPoolTaskExecutor.initialize(165) - Initializing ExecutorService  'clientInboundChannelExecutor'
2018-02-13;00:31:28.976 [main] INFO 
                o.s.s.c.ThreadPoolTaskExecutor.initialize(165) - Initializing ExecutorService  'clientOutboundChannelExecutor'
2018-02-13;00:31:29.434 [main] INFO 
                o.s.s.c.ThreadPoolTaskScheduler.initialize(165) - Initializing ExecutorService  'messageBrokerTaskScheduler'
2018-02-13;00:31:29.567 [main] INFO 
                o.s.w.s.s.s.WebSocketHandlerMapping.registerHandler(362) - Mapped URL path [/websocket/**] onto handler of type [class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]
2018-02-13;00:31:29.627 [main] INFO 
                o.s.s.c.ThreadPoolTaskExecutor.initialize(165) - Initializing ExecutorService  'brokerChannelExecutor'
2018-02-13;00:31:30.895 [main] WARN 
                o.a.activemq.broker.BrokerService.checkMemorySystemUsageLimits(2146) - Memory Usage for the Broker (1024mb) is more than the maximum available for the JVM: 512 mb - resetting to 70% of maximum available: 358 mb
2018-02-13;00:31:31.096 [main] INFO 
                o.a.activemq.broker.BrokerService.doStartPersistenceAdapter(671) - Using Persistence Adapter: KahaDBPersistenceAdapter[C:\Users\anash\git\Notfication\activemq-data\localhost\KahaDB]
2018-02-13;00:31:31.111 [JMX connector] INFO 
                o.a.a.broker.jmx.ManagementContext.run(155) - JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
2018-02-13;00:31:31.721 [main] INFO 
                o.a.a.store.kahadb.MessageDatabase.read(191) - KahaDB is version 6
2018-02-13;00:31:31.747 [main] INFO 
                o.a.a.store.kahadb.MessageDatabase.recover(678) - Recovering from the journal @1:1026194
2018-02-13;00:31:31.768 [main] INFO 
                o.a.a.store.kahadb.MessageDatabase.recover(706) - Recovery replayed 253 operations from the journal in 0.037 seconds.
2018-02-13;00:31:31.965 [main] INFO 
                o.a.a.s.kahadb.plist.PListStoreImpl.doStart(371) - PListStore:[C:\Users\anash\git\Notfication\activemq-data\localhost\tmp_storage] started
2018-02-13;00:31:32.136 [main] INFO 
                o.a.activemq.broker.BrokerService.doStartBroker(734) - Apache ActiveMQ 5.14.5 (localhost, ID:SPS-Anash-49217-1518474691990-0:1) is starting
2018-02-13;00:31:32.159 [main] INFO 
                o.a.a.t.TransportServerThreadSupport.doStart(69) - Listening for connections at: stomp://127.0.0.1:61613
2018-02-13;00:31:32.160 [main] INFO 
                o.a.a.broker.TransportConnector.start(263) - Connector stomp://127.0.0.1:61613 started
2018-02-13;00:31:32.164 [main] INFO 
                o.a.activemq.broker.BrokerService.doStartBroker(761) - Apache ActiveMQ 5.14.5 (localhost, ID:SPS-Anash-49217-1518474691990-0:1) started
2018-02-13;00:31:32.165 [main] INFO 
                o.a.activemq.broker.BrokerService.doStartBroker(762) - For help or more information please see: http://activemq.apache.org
2018-02-13;00:31:32.169 [main] WARN `

1 个答案:

答案 0 :(得分:0)

您需要在Spring Boot应用上启用Jolokia端点,并在应用外部访问它。

为此,首先需要在pom.xml中添加spring-boot-actuator

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-actuator</artifactId>
</dependency>

然后在application.properties中,禁用Jolokia端点的敏感度:

endpoints.jolokia.sensitive = false

现在您应该可以通过以下方式连接到Jolokia:http://localhost:8080/jolokia尝试从您的hawtio控制台连接到它。

仅供参考,您可以在这里找到hawtio与Spring Boot应用程序集成的实例:
https://github.com/hawtio/hawtio/blob/hawtio-1.5.7/hawtio-sample-springboot/