quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.78k stars 2.68k forks source link

Error: Unsupported method java.net.NetworkInterface.isLoopback0(String, int) is reachable: Native method in Artemis JMS client #1843

Closed gastaldi closed 5 years ago

gastaldi commented 5 years ago

I can't use the org.apache.activemq:artemis-jms-client dependency directly because it fails with the following error when creating the native image:

Error: Unsupported method java.net.NetworkInterface.isLoopback0(String, int) is reachable: Native method. If you intend to use the Java Native Interface (JNI), specify -H:+JNI and see also -H:JNIConfigurationFiles=<path> (use -H:+PrintFlags for details)
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
Call path from entry point to java.net.NetworkInterface.isLoopback0(String, int):
    at java.net.NetworkInterface.isLoopback0(NetworkInterface.java)
    at java.net.NetworkInterface.isLoopback(NetworkInterface.java:411)
    at org.apache.activemq.artemis.utils.UUIDGenerator$1.call(UUIDGenerator.java:269)
    at org.apache.activemq.artemis.utils.UUIDGenerator$1.call(UUIDGenerator.java:265)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.oracle.svm.core.jdk.RuntimeSupport.executeHooks(RuntimeSupport.java:144)
    at com.oracle.svm.core.jdk.RuntimeSupport.executeStartupHooks(RuntimeSupport.java:89)
    at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:144)
    at com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)
middagj commented 5 years ago

You have to enable JNI as specified in the error message. Via Gradle this is done by --enable-jni, via Maven by <enableJni>true</enableJni>. Also you need the following reflect config:

[
  {
    "name" : "org.apache.activemq.artemis.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true
  }, {
    "name" : "org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true
  }
]
gastaldi commented 5 years ago

I can confirm that the quarkus-artemis-jms extension fixes the problem. Here is a sample REST endpoint illustrating how I tested it:

package org.acme;

import javax.inject.Inject;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.Queue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

    @Inject
    ConnectionFactory connectionFactory;

    @GET
    @Path("/produce")
    @Produces(MediaType.TEXT_PLAIN)
    public String produce() {
        try (JMSContext jmsContext = connectionFactory.createContext()) {
            Queue teste = jmsContext.createQueue("TEST");
            jmsContext.createProducer().send(teste, "HELLO JMS WORLD!");
        }
        return "Published";
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String consume() {
        String message = null;
        try (JMSContext jmsContext = connectionFactory.createContext()) {
            Queue teste = jmsContext.createQueue("TEST");
            message = jmsContext.createConsumer(teste).receiveBodyNoWait(String.class);
        }
        return message;
    }
}