hivemq/hivemq-community-edition
GitHub: hivemq/hivemq-community-edition
Stars: 1200 | Forks: 283
++++
bin/run.sh
[IMPORTANT]
At least Java version 11 is required to run HiveMQ CE.
To compile the project and run tests at least Java version 21 is required.
If you are in doubt, you can check the installed Java version by entering `java -version` on your command line.
You can now connect MQTT clients to `:1883`.
[CAUTION]
If you want to connect devices on external networks to HiveMQ CE, please make sure your server is reachable from those networks and the required ports (default: 1883) are accessible through your firewall.
=== Just in Time Builds
Just in time builds for current branches on this repository and for specific commits are available https://hivemq.github.io/nightly-builds/[here].
=== Run with Docker
All releases as well as the current state of the `master` branch are available in the https://hub.docker.com/r/hivemq/hivemq-ce[hivemq/hivemq-ce] repository on DockerHub.
To execute this image, simply run the following command:
## [source,bash]
## docker run --name hivemq-ce -d -p 1883:1883 hivemq/hivemq-ce
To change the default log level you can set the environment variable `HIVEMQ_LOG_LEVEL` when running the container:
## [source,bash]
## docker run --name hivemq-ce -e HIVEMQ_LOG_LEVEL=INFO -d -p 1883:1883 hivemq/hivemq-ce
=== Building from Source
==== Building the Binary Package
Check out the git repository and build the binary package.
## [source,bash]
## ./gradlew hivemqZip
The package `hivemq-ce-.zip` is created in the sub-folder `build/distributions/`.
==== Building the Docker Image
Check out the git repository and build the Docker image.
## [source,bash]
## ./gradlew loadOciImage
The Docker image `hivemq/hivemq-ce:snapshot` is created locally.
=== Embedded Mode
==== Gradle
If you use Gradle, include the following code in your `build.gradle(.kts)` file.
## [source,groovy]
## dependencies {
implementation("com.hivemq:hivemq-community-edition-embedded:2026.5")
}
==== Maven
If you use Maven, include the following code in your `pom.xml` file.
## [source,xml]
...
com.hivemq
hivemq-community-edition-embedded
2026.5
...
----
NOTE: You must set the compiler version to `11` or higher.
==== Usage
Entry into the embedded mode is done with the `com.hivemq.embedded.EmbeddedHiveMQBuilder`.
## [source,java]
public class Main {
public static void main(String[] args) {
final EmbeddedHiveMQBuilder embeddedHiveMQBuilder = EmbeddedHiveMQ.builder()
.withConfigurationFolder(Path.of("/path/to/embedded-config-folder"))
.withDataFolder(Path.of("/path/to/embedded-data-folder"))
.withExtensionsFolder(Path.of("/path/to/embedded-extensions-folder"));
...
}
## }
Once built, an EmbeddedHiveMQ can be started with `start()`.
## [source,java]
public class Main {
public static void main(String[] args) {
final EmbeddedHiveMQBuilder embeddedHiveMQBuilder = EmbeddedHiveMQ.builder();
...
try (final EmbeddedHiveMQ hiveMQ = embeddedHiveMQBuilder.build()) {
hiveMQ.start().join();
...
} catch (final Exception ex) {
ex.printStackTrace();
}
}
## }
A running EmbeddedHiveMQ can be stopped with `stop()`.
## [source,java]
public class Main {
public static void main(String[] args) {
...
try (final EmbeddedHiveMQ hiveMQ = embeddedHiveMQBuilder.build()) {
...
hiveMQ.stop().join();
} catch (final Exception ex) {
ex.printStackTrace();
}
}
## }
Similar to the embedded HiveMQ an embedded extension can be built with the `com.hivemq.embedded.EmbeddedExtensionBuilder`.
Then add the embedded extension to the embedded HiveMQ builder.
## [source,java]
public class Main {
public static void main(String[] args) {
final EmbeddedExtension embeddedExtension = EmbeddedExtension.builder()
.withId("embedded-ext-1")
.withName("Embedded Extension")
.withVersion("1.0.0")
.withPriority(0)
.withStartPriority(1000)
.withAuthor("Me")
.withExtensionMain(new MyEmbeddedExtensionMain())
.build();
final EmbeddedHiveMQBuilder builder = EmbeddedHiveMQ.builder()
.withConfigurationFolder(Path.of("/path/to/embedded-config-folder"))
.withDataFolder(Path.of("/path/to/embedded-data-folder"))
.withExtensionsFolder(Path.of("/path/to/embedded-extensions-folder"))
.withEmbeddedExtension(embeddedExtension);
try (final EmbeddedHiveMQ hiveMQ = builder.build()) {
hiveMQ.start().join();
//do something with hivemq
} catch (final Exception ex) {
ex.printStackTrace();
}
}
private static class MyEmbeddedExtensionMain implements ExtensionMain {
@Override
public void extensionStart(final @NotNull ExtensionStartInput extensionStartInput, final @NotNull ExtensionStartOutput extensionStartOutput) {
// my extension start code
}
@Override
public void extensionStop(final @NotNull ExtensionStopInput extensionStopInput, final @NotNull ExtensionStopOutput extensionStopOutput) {
// my extension stop code
}
}
## }
NOTE: An EmbeddedHiveMQ is a resource that is similar to a e.g. network connection and implements the `java.lang.AutoCloseable` interface.
Always use ARM (_try with resources_) or ensure a call to `close()`.
==== Exclusions
When you deploy an application that includes EmbeddedHiveMQ, it can be useful to exclude some dependencies.
One way to exclude dependencies is with the link:https://maven.apache.org/plugins/maven-shade-plugin/[maven shade plugin].
## [source,xml]
...
org.apache.maven.plugins
maven-shade-plugin
3.2.1
package
shade
org.rocksdb:rocksdbjni
ch.qos.logback:logback-classic
*:*
META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA
...
----
===== RocksDB Exclusion
To exclude the `org.rocksdb:rocksdbjni` dependency, two internal configurations must be changed before you call `start()`.
## [source,java]
public class Main {
public static void main(String[] args) {
...
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();
}
}
## }
// Scarf Tracking Pixel
== License
== License标签:域名枚举