HiveMQ

Implementing extension with MongoDB database driver

Hi,

I am using the steps provided in the following link to implement a simple extension to intercept clientId, topics names, and message’s and log them to a MongoDB.

https://www.hivemq.com/docs/hivemq/4.4/extensions/introduction.html

I am runnin the following command which generates the required file’s…

mvn archetype:generate -DarchetypeGroupId=com.hivemq -DarchetypeArtifactId=hivemq-extension-archetype -DarchetypeVersion=4.4.8

…But I do not know how to include the MongoDB driver in the command.

Request you to help.

Regards,
Harsha

Hello Harsha,

you can not include the version of the MongoDB database driver in the command. But you can add the mongoDB driver manually to the pom.xml once the project is created with the command.

Step 1: Create the Project with the command

mvn archetype:generate -DarchetypeGroupId=com.hivemq -DarchetypeArtifactId=hivemq-extension-archetype -DarchetypeVersion=4.4.8

Step 2: Add your MongoDB driver dependency to the generated pom.xml:

<project>
   ...
    <dependencies>
        <dependency>
            <groupId>com.hivemq</groupId>
            <artifactId>hivemq-extension-sdk</artifactId>
            <version>4.4.8</version>
        </dependency>
       <dependency>
           <groupId>org.mongodb</groupId>
           <artifactId>mongodb-driver</artifactId>
           <version>3.12.8</version>
       </dependency>
    </dependencies>
   ....
</project>

Regards,
Yannick

1 Like

Thank you Yannick.

Sorry I am new to this. Is there any command I need to run after modifying the pom.xml to actually install the drivers ?

Regards,
Harsha

Hello Harsha,

Running mvn compile should download all declared dependencies.
See: Maven – Introduction to the Build Lifecycle

Regards,
Yannick

Thank you Yannick.

Regards,
Harsha

Hi,

I am using the hello word plugin to log published data to MongoDB. I am trying to find the syntax to get the client id and message payload. I am able to get the topic name in the “HelloWorldInterceptor.java” file which is created when I run the command

mvn archetype:generate -DarchetypeGroupId=com.hivemq -DarchetypeArtifactId=hivemq-extension-archetype -DarchetypeVersion=4.6.3 -DhivemqExtensionSdkVersion=4.4.9

System.out.println(publishPacket.getTopic())

Also how do I locate API’s if I need to make more modification’s ? I am new to Java and have basic understanding of OOP concepts.

Regards,
Harsha

Answered here: Need help with HiveMQ SDK API's