Logging Issue regarding Embedded MQTT Broker in OSGi Environment

Hi all,
for my current project I try to incorporate EmbeddedHiveMQ into an existing OSGi environment (based on Equinox).

So far, I created my Service-Component as proposed by the Github README:

  public void activate() {
      final EmbeddedHiveMQBuilder embeddedHiveMQBuilder = EmbeddedHiveMQ.builder();
      ...

      try (final EmbeddedHiveMQ hiveMQ = embeddedHiveMQBuilder.build()) {
          hiveMQ.start().join();
          ...
      } catch (final Exception ex) {
          ex.printStackTrace();
      }
  }

Now, the start() method throws me a ClassCastException during the LoggingBootstrap:

!STACK 0
java.util.concurrent.CompletionException: java.lang.ClassCastException: class ch.qos.logback.classic.LoggerContext cannot be cast to class ch.qos.logback.classic.LoggerContext (ch.qos.logback.classic.LoggerContext is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @f14a7d4; ch.qos.logback.classic.LoggerContext is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @673d71d5)
	at java.base/java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:413)
	at java.base/java.util.concurrent.CompletableFuture.join(CompletableFuture.java:2118)
...
	at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:343)
Caused by: java.lang.ClassCastException: class ch.qos.logback.classic.LoggerContext cannot be cast to class ch.qos.logback.classic.LoggerContext (ch.qos.logback.classic.LoggerContext is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @f14a7d4; ch.qos.logback.classic.LoggerContext is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @673d71d5)
	at com.hivemq.bootstrap.LoggingBootstrap.getRootLogger(LoggingBootstrap.java:145)
	at com.hivemq.bootstrap.LoggingBootstrap.prepareLogging(LoggingBootstrap.java:67)
...

Obviously OSGi uses seperate class loaders on a per bundle basis and I have already a bundle to setup logging (also backed by logback as HiveMQ does). Here I have some collisions regarding the casts done in the com.hivemq.bootstrap.LoggingBootstrap class.

As a workaround I commented all calls to com.hivemq.bootstrap.LoggingBootstrap in class com.hivemq.HiveMQServer’s bootstrap() method (only 3 places) to entirely disable the setup of any specific logging and this eventually worked!

So my questions are:
Does anyone have experience incorporating HiveMQ into OSGi environment?
Are there any arguments against deactivating logging as I did for my purpose?
And @ForumMaintainers: If there are no arguments against it, is it worth opening an Issue/Pull Request to get com.hivemq.embedded.EmbeddedHiveMQBuilder changed to programmatically deactivate logging during setup?

Best regards,
janosch

Hi @janosch

Thank you for reaching out, and we’re glad to hear that you were able to find a workaround for the logging issue in your OSGi environment. Your detailed explanation of the problem and the solution you implemented is greatly appreciated.

We understand the challenges that can arise when integrating HiveMQ into diverse environments, and your experience with OSGi sheds light on a potential improvement. Disabling logging programmatically, as you’ve done, seems like a viable workaround in your case.

We encourage you to contribute your insights by opening an Issue or Pull Request on our GitHub repository. This could be a valuable addition to the HiveMQ community, especially for users facing similar challenges in OSGi environments.

Your effort to share your experience and suggest a solution is highly commendable, and we welcome any contributions that enhance the overall usability of HiveMQ. If you decide to proceed with a Pull Request, our development team will thoroughly review it to ensure compatibility and coherence with the project’s goals.

Once again, thank you for bringing this to our attention, and we appreciate your proactive approach to finding solutions. If you have any further questions or need assistance during the contribution process, feel free to reach out.

Best regards,
Dasha from HiveMQ Team

1 Like

Hi @Daria_H,
thank you very much for your reply.
I will open Issue/pull request asap.
My plan is to incorporate EmbeddedHiveMQBuilder to programmatically switch off logging.

Meanwhile I have my changes in production since a few month.
No issues, works like a charm …

Thanks again for your advice!
Best regards,
janosch