eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.1k stars 880 forks source link

Support GraalVM native images #963

Open joshlong opened 1 year ago

joshlong commented 1 year ago

Hello,

I'm trying to make the spring integration mqtt support work in a GraalVM native image context. It breaks in eclipse paho's amazing (thank you for the good work) mqtt client as there some places where reflection is required and where resources are loaded from the classpath.

I originally submitted some proposed changes to the spring integration project but they wisely forwarded me here to you.

Here's the original issue:

https://github.com/spring-projects/spring-integration/issues/3900

GraalVM will look for .json Config files in the META-INF/native-image/ of all jars it finds on the classpath. You could ship those with no code changes and help me get at least my example working.

I link to some code in the Spring Integration issue to which I've linked you that programmatically contributes the configurations my app needed to work in a GraalVM native image context. It would be straightforward to translate that into static .json files and add those to your project. I might give it a go myself...

Thanks for your work and for your consideration

artembilan commented 1 year ago

This is what we see so far as working native configs:

  1. resource-config.json
    {
    "bundles": [
    {
      "name": "org\/eclipse\/paho\/client\/mqttv3\/internal\/nls\/messages"
    },
    {
      "name": "org\/eclipse\/paho\/client\/mqttv3\/internal\/nls\/logcat"
    },
    {
      "name": "org\/eclipse\/paho\/mqttv5\/common\/nls\/messages"
    },
    {
      "name": "org\/eclipse\/paho\/mqttv5\/client\/internal\/nls\/logcat"
    }
    ]
    }
  2. reflect-config.json:
    [
    {
    "name": "org.eclipse.paho.client.mqttv3.logging.JSR47Logger",
    "allPublicConstructors": true
    },
    {
    "name": "org.eclipse.paho.mqttv5.client.logging.JSR47Logger",
    "allPublicConstructors": true
    }
    ]

Although v3 and v5 stuff definitely must be devided between respective modules in this project.