hivemq / hivemq-edge

HiveMQ Edge is an MQTT gateway that enables interoperability between OT devices and IT systems. It translates diverse protocols into MQTT for streamlined communication and helps organize data into a unified namespace, making managing and streaming data across your infrastructure easier.
http://hivemq.com
Apache License 2.0
90 stars 20 forks source link

Building EmbeddedHiveMQ has no extension #432

Open smtlmoel opened 1 month ago

smtlmoel commented 1 month ago

I have added the HiveMQ Embedded Broker CE to my custom adapter and for this embedded broker I wanted to add an InboundInterceptor.

I set up the embedded broker like told in the docu:

final EmbeddedExtension embeddedExtension = EmbeddedExtension.builder()
                .withId("embedded-ext-1")
                .withName("Embedded Extension")
                .withVersion("1.0.0")
                .withPriority(-100)
                .withStartPriority(1000)
                .withAuthor("Me")
                .withExtensionMain(new CustomInterceptor())
                .build();

final EmbeddedHiveMQBuilder embeddedHiveMQBuilder = EmbeddedHiveMQ.builder()
                .withConfigurationFolder(configFile.toPath())
                .withDataFolder(getDataFolder().toPath())
                .withExtensionsFolder(getExtensionFolder().toPath()));

final EmbeddedHiveMQ hiveMQ = embeddedHiveMQBuilder.build();

But when I call the build() method of my EmbeddedHiveMQBuilder the function only returns an EmbeddedHiveMQImpl() without the embedded ectension.

See file EmbeddedHiveMQBuilderImpl, line 78.

I am not sure if this is intended or needs to be fixed.

DC2-DanielKrueger commented 3 weeks ago

Hey @smtlmoel, thx for raising this. I think you are missing to add the embedded extension via .withEmbeddedExtension(embeddedExtension) on the builder. Can you check if this works for you?

        final EmbeddedExtension embeddedExtension = EmbeddedExtension.builder()
                .withId("embedded-ext-1")
                .withName("Embedded Extension")
                .withVersion("1.0.0")
                .withPriority(-100)
                .withStartPriority(1000)
                .withAuthor("Me")
                .withExtensionMain(new CustomInterceptor())
                .build();

        final EmbeddedHiveMQBuilder embeddedHiveMQBuilder = EmbeddedHiveMQ.builder()
                .withEmbeddedExtension(embeddedExtension)
                .withConfigurationFolder(configFile.toPath())
                .withDataFolder(getDataFolder().toPath())
                .withExtensionsFolder(getExtensionFolder().toPath()));

        final EmbeddedHiveMQ hiveMQ = embeddedHiveMQBuilder.build(); 

Best regards, Daniel

smtlmoel commented 3 weeks ago

Hello @DC2-DanielKrueger,

yeah that helped starting an embedded HiveMQ with an extension.

But now I have the follow up problem that the default broker started by the edge and my started embedded broker conflict.

Is there any way to consume incomming messages from the default broker on port 1883, modify these and then publish the transformed message to the internal broker?

Starting the HiveMQ Edge with the hivemq-allow-all-extension does not allow me to connect with an internal client to the default broker and to consume the incomming messages.

Best regards, Till

DC2-DanielKrueger commented 2 weeks ago

Hello @smtlmoel, I'm a bit confused how your setup looks like and what you want to achieve? Why are there two instances of Edge running? Can you explain your setup a bit and hopefully I can help you better. You can chain the brokers together using bridges.

Best regards, Daniel

smtlmoel commented 6 days ago

Hi @DC2-DanielKrueger,

my setup look the way that I start a second broker in my CustomAdapter. The reason is that I have an internal client also running in the CustomAdapter which is subscribed to specific topics. The internal client then stores the incomming messages and after a limit is reached a a new message (batch), containing alle the stored messages, is created and published to the bridge.

I have started the second broker because it was not possible to connect with the internal client to the default broker. The "batching" is required to reduce the load on the side of the bridge because I receive messages every 200ms.

I hope this makes my case more clear.

Best regards Till