This repostory provide a Java SDK based on emqx-extension-hook.
-
JDK 1.8+
-
Depend on
erlport.jar
(The communication module used in emqx-extension-hook)
SDK edition | EMQ X Broker edition |
---|---|
1.0.0 | 4.2.0 |
unsupport | before 4.2.0 |
-
First of all, create your Java project.
-
See
SDK edition & EMQ X Broker edition
part. Chose your SDK edition.Depends on EMQ X Broker edition.Download the io.emqx.extension.jar and erlport.jar
-
Add the sdk:
io.emqx.extension.jar
anderlport.jar
to your project dependency.If your project is a maven project, add a dependency in your maven project
pom.xml
<dependencies></dependencies>
.<dependency> <groupId>io.emqx</groupId> <artifactId>emqx-extension-java-sdk</artifactId> <!-- Chose your SDK edition.Depends on EMQ X Boker edition. --> <!-- Change version to your chosen SDK edition --> <version>1.0.0</version> </dependency>
Change
<version>version</version>
to your chosen SDK edition, like<version>1.0.0</version>
. -
Copy the
examples/SampleHandler.java
into your project. -
Successfully compile all the source codes.
Note: NOT read/write System.out.*
and System.in
Stream. They are used to communicate with EMQ X.
After compiled all source codes, you should deploy the sdk
and your class files into EMQ X.
- Copy the
io.emqx.extension.jar
toemqx/data/extension
directory. - Copy your class files, e.g:
SampleHandler.class
toemqx/data/extension
directory. - Modify the
emqx/etc/plugins/emqx_extension_hook.conf
file. e.g:
exhook.drivers = java
## Search path for scripts or library
exhook.drivers.java.path = data/extension/
exhook.drivers.java.init_module = SampleHandler
- Execute
bin/emqx console
to start EMQ X and load theemqx_extension_hook
plugin. - Try to establish a MQTT connection and observe the console output.
See: examples/SampleHandler.java
Apache License v2