HiveMq Java Client

Has anyone been able to successfully use the HiveMQ java client within Ignition? I have added the jar to my gateways common library folder and I am running the code in the gateway scope. I keep getting stuck on the following:

image

Caused by: org.python.core.PyException: java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class com.hivemq.client.internal.mqtt.MqttClientTransportConfigImpl

... 23 common frames omitted

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.hivemq.client.internal.mqtt.MqttClientTransportConfigImpl

at com.hivemq.client.internal.mqtt.MqttRxClientBuilderBase.(MqttRxClientBuilderBase.java:46)

at com.hivemq.client.internal.mqtt.MqttRxClientBuilderBase$Choose.(MqttRxClientBuilderBase.java:216)

at com.hivemq.client.mqtt.MqttClient.builder(MqttClient.java:59)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:190)

... 20 common frames omitted

Tip: post code - not pictures of code. That way it doesn't have to be typed out in answers to your question. Post a screengrab as well if the context is relevant to the question. See Wiki - how to post code on this forum.

What jar file(s) have you added?

hivemq-mqtt-client-1.3.3.jar found here Maven Repository: com.hivemq » hivemq-mqtt-client » 1.3.3 (mvnrepository.com)

Is there a dependency that I am unaware of?

Seems so

Are those dependencies for building the jar or are those dependencies outside the jar that are needed to use the jar?

Any of those JARs that aren't already part of Ignition are at least needed at runtime for execution. And so on if they have any of their own dependencies.

Thanks. I was able to get passed that error. I built the shaded JAR and then it still had a dependency that was not being included in the shaded JAR for rxjava-2.2.21.jar. I just added that JAR separate in the common folder.

Now, I am getting stuck on a different error. Could you shine any light on what might be causing this?

Following an example from here looks like it is failing on line 16 where it does .payload()

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 16, in handleMessage at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source) at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalAccessException: java.lang.IllegalAccessException: class org.python.core.PyReflectedFunction cannot access a member of class com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder$Base with modifiers "public"

at org.python.core.Py.JavaError(Py.java:547)

at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:192)

at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:208)

at org.python.core.PyObject.call(PyObject.java:477)

at org.python.core.PyObject.call(PyObject.java:481)

at org.python.core.PyMethod.call(PyMethod.java:141)

at org.python.pycode._pyx1282.handleMessage$1(:24)

at org.python.pycode._pyx1282.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyBaseCode.call(PyBaseCode.java:306)

at org.python.core.PyFunction.function___call__(PyFunction.java:474)

at org.python.core.PyFunction.call(PyFunction.java:469)

at org.python.core.PyFunction.call(PyFunction.java:464)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)

at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:852)

at com.inductiveautomation.ignition.common.script.message.MessageHandlerRunnable.run(MessageHandlerRunnable.java:114)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: java.lang.IllegalAccessException: java.lang.IllegalAccessException: class org.python.core.PyReflectedFunction cannot access a member of class com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder$Base with modifiers "public"

... 23 common frames omitted

Caused by: java.lang.IllegalAccessException: class org.python.core.PyReflectedFunction cannot access a member of class com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder$Base with modifiers "public"

at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source)

at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.call(PyReflectedFunction.java:190)

... 21 common frames omitted

Finally figured it out, with the help of this post Using Java.net Socket - #13 by pturmel

Looks like this last error had to do with Java overloading methods. Using reflection I can get the method from the class using the method name and parameter types. Then once I get the method from the class I can use the invoke method on the method returned from get method passing in my instance of the class object, along with parameter values. This is on line 22 and 24.

3 Likes

Yuck, good job figuring that out. Not sure I would have ended up there.