Undesired dependency to rocksdb in EmbeddedHiveMQ?

Hi to everyone,

currently I try to incorporate EmbeddedHiveMQ into another application.
What I want to use is in-memory persistence. So, according to the Community Edition Github README I excluded rocksdb (I use gradle’s ShadowJar plugin to get a shaded version of HiveMQ-CE as a single JAR archive):

plugins {
    id 'java-library'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
}

// https://imperceptiblethoughts.com/shadow/
shadowJar {
    archiveBaseName.set('hivemq-ce-embedded-shaded' + '-no-rocksdb')
    archiveClassifier.set('')

    dependencies {
        exclude(dependency('org.rocksdb:rocksdbjni'))
        exclude(dependency('ch.qos.logback:logback-classic'))
    }
}

Consistently I start my embedded broker as recommended by the README:

try (final EmbeddedHiveMQ hiveMQ = embeddedHiveMQBuilder.build()) {

    InternalConfigurations.PAYLOAD_PERSISTENCE_TYPE.set(PersistenceType.FILE);
    InternalConfigurations.RETAINED_MESSAGE_PERSISTENCE_TYPE.set(PersistenceType.FILE);

    hiveMQ.start().join();

    ...
} catch (final Exception ex) {
    ex.printStackTrace();
}

Nevertheless I get an exception thrown during startup:

!STACK 0
java.lang.NoClassDefFoundError: org/rocksdb/CompressionType
	at com.hivemq.configuration.service.InternalConfigurations.<clinit>(InternalConfigurations.java:296)
...
Caused by: java.lang.ClassNotFoundException: org.rocksdb.CompressionType cannot be found by ...
...

Did I miss something?

Best regards,
janosch

Did you also change the config file and added this?

    <persistence>
        <mode>in-memory</mode>
    </persistence>

Hi @basimons,
thanks for your reply.
Yes I have exactly this entry in my configuration file.

Meanwhile I changed my gradle shadow configuration to not exclude all rocksdb stuff but just the binaries.
Instead of

dependencies {
        exclude(dependency('org.rocksdb:rocksdbjni'))
}

I used this:

dependencies {
    exclude 'librocksdbjni*'
}

By doing so it saved me approx. 50 MB file size of the shaded jar-file.
And it works now with in-memory persistence.

Best regards,
janosch

2 Likes