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

Has there been any progress on this problem? I have the same issue. I’m not using OSGi, but I have an embedded HiveMQ instance running inside a Spring Boot application. HiveMQ and Spring Boot clash since they’re both trying to bootstrap Logback. The ability to disable bootstrapping via the EmbeddedHiveMQBuilder would be great.

Hi @toellrich,
I have currently an open pull request regarding this issue, but my cla confirmation is still hanging … :roll_eyes:
Meanwhile you may checkout my fork (which is up-to-date) at: GitHub - janosch24/hivemq-community-edition: HiveMQ CE is a Java-based open source MQTT broker that fully supports MQTT 3.x and MQTT 5. It is the foundation of the HiveMQ Enterprise Connectivity and Messaging Platform
There is a branch improvement/logging-issue-regarding-osgi

Best regards,
Jan

@Daria_H
I filled the cla form which is required for the pull request, but it seems still be not ok.
Do I have to send it somewhere?

1 Like

Hi @janosch ,

Thanks, for now I’m using an embedded ActiveMQ Artemis server with MQTT protocol enabled as a workaround. I might not actually need HiveMQ.

Best regards,
Thomas

Hi @toellrich,
o.k., you should be fine with Artemis embedded.
But don’t forget the possibility to use either native or even embedded extensions.
HiveMQ gives great opportunities … :wink:
Nevertheless I will do a test with Spring Boot next time.
If you are interested, I will tell you the results.

Regards,
Jan

Hi @janosch,

definitely interested. Keep me up to date.

Cheers,
Thomas