Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOT support for MQTT + Eclipse Paho #3900

Closed
joshlong opened this issue Oct 1, 2022 · 4 comments
Closed

AOT support for MQTT + Eclipse Paho #3900

joshlong opened this issue Oct 1, 2022 · 4 comments
Labels
in: mqtt status: declined There won't be a fix for some reason type: enhancement

Comments

@joshlong
Copy link
Member

joshlong commented Oct 1, 2022

Hi, i love your MQTT support, but MQTT Paho doesn't work out-of-the-box in an AOT context. I crafted some hints that make my example work. Perhaps you would consider including them for others?

Here's the commit demonstrating the hints and a pretty typical inbound/outbound example w/ Spring Integration MQTT

Here's the hints, if for whatever reason that github repo should be lost:

    static class MqttHints implements RuntimeHintsRegistrar {

        @Override
        public void registerHints(RuntimeHints hints, ClassLoader classLoader) {

            var classes = new Class<?>[]{
                    JSR47Logger.class,
                    LoggerFactory.class,
                    NetworkModuleFactory.class,
                    WebSocketNetworkModuleFactory.class,
                    WebSocketSecureNetworkModuleFactory.class,
                    SSLNetworkModuleFactory.class,
                    TCPNetworkModuleFactory.class,
                    Logger.class};

            var resources = Map.of(
                    "org/eclipse/paho/client/mqttv3/logging/JSR47Logger.class", false, //
                    "org/eclipse/paho/client/mqttv3/internal/nls/logcat.properties", false, //
                    "org/eclipse/paho/client/mqttv3/internal/nls/messages", true
            );

            for (var c : classes) {
                hints.reflection().registerType(c, MemberCategory.values());
            }

            for (var entry : resources.entrySet()) {
                var bundle = entry.getValue();
                var path = entry.getKey();
                if (bundle)
                    hints.resources().registerResourceBundle(path);
                else
                    hints.resources().registerPattern(path);

            }
        }
    }
@joshlong joshlong added status: waiting-for-triage The issue need to be evaluated and its future decided type: enhancement labels Oct 1, 2022
@artembilan artembilan changed the title please support AOT for MQTT + Eclipse Paho AOT support for MQTT + Eclipse Paho Oct 3, 2022
@artembilan
Copy link
Member

Hi @joshlong !

You know it is better to ask for this support directly in Eclipe Paho project: https://github.com/eclipse/paho.mqtt.java
As it is states by the GraalVM reachability metadata repo contribution: https://github.com/oracle/graalvm-reachability-metadata/blob/master/CONTRIBUTING.md.

Also I think some of your hints are redundant or erroneous.

  1. The ServiceLoader is supported by GraalVM as out-of-the-box feature, so we don't need many of those classes to register manually for reflection: Automatically register classes in META-INF/services for reflection. oracle/graal#563 (comment).
    We need to double check with modern GraalVM version to be sure in our (Eclipse Paho) extra hints.
  2. I'm not sure why org/eclipse/paho/client/mqttv3/logging/JSR47Logger.class is marked as a resource in your case...

Out of scope: Spring Integration also supports MQTT V5 if that is useful for your sample though: https://docs.spring.io/spring-integration/docs/current/reference/html/mqtt.html#mqtt-v5

@artembilan artembilan added status: waiting-for-reporter Needs a feedback from the reporter and removed status: waiting-for-triage The issue need to be evaluated and its future decided labels Oct 3, 2022
@joshlong
Copy link
Member Author

joshlong commented Oct 3, 2022

Alright, I've raised an issue there. I hope they're able to do this before we go GA w spring boot. it would be amazing to have all the major modules working out of the box in spring integration when Boot goes GA.

eclipse/paho.mqtt.java#963

@artembilan
Copy link
Member

This is working config for the current GraalVM and Spring AOT support:

	static class MqttHints implements RuntimeHintsRegistrar {

		@Override
		public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
			ReflectionHints reflectionHints = hints.reflection();
			Stream.of(
							"org.eclipse.paho.client.mqttv3.logging.JSR47Logger",
							"org.eclipse.paho.mqttv5.client.logging.JSR47Logger")
					.forEach(type -> reflectionHints.registerTypeIfPresent(classLoader, type,
							MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));

			ResourceHints resources = hints.resources();
			Stream.of(
							"org/eclipse/paho/client/mqttv3/internal/nls/messages",
							"org/eclipse/paho/client/mqttv3/internal/nls/logcat",
							"org/eclipse/paho/mqttv5/common/nls/messages",
							"org/eclipse/paho/mqttv5/client/internal/nls/logcat")
					.forEach(resources::registerResourceBundle);
		}

	}

Closed in favor of linked Eclipse Paho issue.

@artembilan artembilan closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2022
@artembilan artembilan added in: mqtt status: declined There won't be a fix for some reason and removed status: waiting-for-reporter Needs a feedback from the reporter labels Oct 3, 2022
@artembilan
Copy link
Member

FYI the native image support has made it into Rome code base: rometools/rome#599

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mqtt status: declined There won't be a fix for some reason type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants