0

I'm running the hivemq mqtt broker community edition and wanted to add the prometheus extension for monitoring.
Both come precompiled from the hivemq marketplace and the github project page.
I download both components as a zip file, unzip them and copy them into a java 11 docker container using this dockerfile:

FROM alpine:3.10  AS TOOLCHAIN
ADD https://github.com/hivemq/hivemq-community-edition/releases/download/2019.1/hivemq-ce-2019.1.zip /opt/
ADD https://www.hivemq.com/releases/extensions/hivemq-prometheus-extension-4.0.1.zip /opt/
WORKDIR /opt
RUN unzip hivemq-ce-* -d ./
RUN unzip hivemq-prometheus-extension* -d ./
RUN rm -rf hivemq-ce-*.zip
RUN rm -rf hivemq-prometheus-extension*.zip
RUN mv ./hivemq-ce-* ./hivemq

FROM openjdk:11-jdk-slim
COPY --from=TOOLCHAIN /opt/hivemq /opt/hivemq
COPY --from=TOOLCHAIN /opt/hivemq-prometheus-extension /opt/hivemq/extensions/hivemq-prometheus-extension
WORKDIR /opt/hivemq/
CMD ["chmod","755","./bin/run.sh"]
CMD ["./bin/run.sh"]

I think I got the steps from the how to's right, but when I start the container with docker build -t hive-test .; docker run -p 1883:1883 -p 9399:9399 -t hive-test I get an error.

2019-07-24 13:19:57,125 INFO  - Starting HiveMQ Community Edition Server
2019-07-24 13:19:57,127 INFO  - HiveMQ version: 2019.1
2019-07-24 13:19:57,127 INFO  - HiveMQ home directory: /opt/hivemq
2019-07-24 13:19:57,162 INFO  - Log Configuration was overridden by /opt/hivemq/conf/logback.xml
2019-07-24 13:19:57,356 INFO  - This HiveMQ ID is mwDbQ
2019-07-24 13:20:14,353 INFO  - Created user preferences directory.
2019-07-24 13:20:14,873 INFO  - Starting HiveMQ extension system.
2019-07-24 13:20:14,925 INFO  - Starting TCP listener on address 0.0.0.0 and port 1883
2019-07-24 13:20:14,998 INFO  - Started TCP Listener on address 0.0.0.0 and on port 1883
2019-07-24 13:20:14,999 INFO  - Started HiveMQ in 17877ms
2019-07-24 13:20:15,040 ERROR - Extension with id "hivemq-prometheus-extension" cannot be started because of an uncaught exception thrown by the extension. Extension will be disabled.
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
        at org.eclipse.jetty.server.handler.ContextHandler.<clinit>(ContextHandler.java:114)
        at com.hivemq.extensions.prometheus.export.PrometheusServer.start(PrometheusServer.java:64)
        at com.hivemq.extensions.prometheus.PrometheusMainClass.extensionStart(PrometheusMainClass.java:65)
        at com.hivemq.extensions.HiveMQExtensionImpl.start(HiveMQExtensionImpl.java:133)
        at com.hivemq.extensions.HiveMQPlugins.pluginStart(HiveMQPlugins.java:209)
        at com.hivemq.extensions.loader.PluginLifecycleHandlerImpl.lambda$startPlugin$0(PluginLifecycleHandlerImpl.java:82)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
        at com.hivemq.extensions.classloader.IsolatedPluginClassloader.loadClass(IsolatedPluginClassloader.java:123)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 9 common frames omitted

I also downloaded the broker and extension source code and tried to compile it by myself with maven/gradle and java 11. But that had the exact same result.

The broker runs without any errors.

Does anyone know what went wrong here?

JWo
  • 650
  • 1
  • 6
  • 23

1 Answers1

0

Actually no dependency from the hivemq broker community edition contains ServletContextListener. I downloaded the source code from github and modified the build.gradle file.

Add the last line of the following snippet to the build.gradle file:

/* javax */
[group: 'javax.activation', name: 'activation', version: '1.1.1'],
[group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'],
[group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'],
[group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'],

After compiling the broker unzip the result and add the precompiled extension to the extension directory.

The error is gone and the extension seems to be working.

JWo
  • 650
  • 1
  • 6
  • 23