datastax / pulsar-jms

DataStax Starlight for JMS, a JMS API for Apache Pulsar ®
Apache License 2.0
48 stars 21 forks source link

Fail to create JMSContext with NoSuchMethodError exception #6

Closed yabinmeng closed 3 years ago

yabinmeng commented 3 years ago

I'm testing Pulsar JMS against a Pulsar 2.7. 2 cluster (with authentication and authorization enabled).

The JMS configuration is as below:

## Pulsar Client connection configuration
# - https://pulsar.apache.org/docs/en/reference-configuration/#client
webServiceUrl=http://<pulsar_server_ip>:8080
brokerServiceUrl=pulsar://<pulsar_server_ip>:6650
authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken
authParams=token:xxxx

## JMS specific configuration
jms.queueSubscriptionName=myjms-queue

The application code is simple as this:

  public class JmsClientConn {

    private Map<String, Object> jmsConnMap = new HashMap<>();
    private JMSContext jmsContext = null;
    private boolean isQueue;
    private String destName;
    private Destination destination = null;

    JmsClientConn(boolean isQueue, String destName, Map<String, Object> jmsConnMap) {
        this.isQueue = isQueue;
        this.destName = destName;
        this.jmsConnMap = jmsConnMap;
        createJmsClient();
    }

    void createJmsClient() {
        PulsarConnectionFactory factory = null;
        try {
            factory = new PulsarConnectionFactory(jmsConnMap);
            jmsContext = factory.createContext();

            if (isQueue)
                destination = jmsContext.createQueue(destName);
            else
                destination = jmsContext.createTopic(destName);
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }

    public JMSContext getJmsContext() { return jmsContext; }

    public Destination getDestination() { return destination; }
}

The above application fails when trying to create the JMS Context

            jmsContext = factory.createContext();

The exception is as below:

Exception in thread "main" javax.jms.JMSRuntimeException: java.lang.NoSuchMethodError: 'java.util.concurrent.TimeoutException org.apache.pulsar.common.util.FutureUtil.createTimeoutException(java.lang.String, java.lang.Class, java.lang.String)'
    at com.datastax.oss.pulsar.jms.Utils.throwAsRuntimeException(Utils.java:282)
    at com.datastax.oss.pulsar.jms.Utils.runtimeException(Utils.java:231)
    at com.datastax.oss.pulsar.jms.PulsarConnectionFactory.createContext(PulsarConnectionFactory.java:688)
    at com.datastax.oss.pulsar.jms.PulsarConnectionFactory.createContext(PulsarConnectionFactory.java:462)
    at com.example.jms.JmsClientConn.createJmsClient(JmsClientConn.java:30)
    at com.example.jms.JmsClientConn.<init>(JmsClientConn.java:23)
    at com.example.jms.JmsDemoApp.main(JmsDemoApp.java:161)
Caused by: javax.jms.JMSException: java.lang.NoSuchMethodError: 'java.util.concurrent.TimeoutException org.apache.pulsar.common.util.FutureUtil.createTimeoutException(java.lang.String, java.lang.Class, java.lang.String)'
    at com.datastax.oss.pulsar.jms.Utils.handleException(Utils.java:63)
    at com.datastax.oss.pulsar.jms.PulsarConnectionFactory.ensureInitialized(PulsarConnectionFactory.java:318)
    at com.datastax.oss.pulsar.jms.Utils.runtimeException(Utils.java:226)
    ... 5 more
Caused by: java.lang.NoSuchMethodError: 'java.util.concurrent.TimeoutException org.apache.pulsar.common.util.FutureUtil.createTimeoutException(java.lang.String, java.lang.Class, java.lang.String)'
    at org.apache.pulsar.client.admin.internal.http.AsyncHttpConnector.<clinit>(AsyncHttpConnector.java:76)
    at org.apache.pulsar.client.admin.internal.http.AsyncHttpConnectorProvider.getConnector(AsyncHttpConnectorProvider.java:52)
    at org.apache.pulsar.client.admin.internal.PulsarAdminImpl.<init>(PulsarAdminImpl.java:200)
Caused by: javax.jms.JMSException: java.lang.NoSuchMethodError: 'java.util.concurrent.TimeoutException org.apache.pulsar.common.util.FutureUtil.createTimeoutException(java.lang.String, java.lang.Class, java.lang.String)'

    at org.apache.pulsar.client.admin.internal.PulsarAdminBuilderImpl.build(PulsarAdminBuilderImpl.java:47)
    at com.datastax.oss.pulsar.jms.PulsarConnectionFactory.ensureInitialized(PulsarConnectionFactory.java:285)
    ... 6 more
Caused by: java.lang.NoSuchMethodError: 'java.util.concurrent.TimeoutException org.apache.pulsar.common.util.FutureUtil.createTimeoutException(java.lang.String, java.lang.Class, java.lang.String)'
eolivelli commented 3 years ago

Do you have Pulsar client in the classpath together with the jms client?

It looks like there is some mismatch in the classpath

yabinmeng commented 3 years ago

My build.gradle file is this:

dependencies {
    // https://mvnrepository.com/artifact/com.datastax.oss/pulsar-jms
    implementation group: 'com.datastax.oss', name: 'pulsar-jms', version: '1.1.0'

    // https://mvnrepository.com/artifact/org.apache.pulsar/pulsar-client
    implementation group: 'org.apache.pulsar', name: 'pulsar-client', version: '2.7.2'
   ... 

I'm running the program from inside Intellij.

yabinmeng commented 3 years ago

You're right.

Pulsar JMS has dependency on Pulsar 2.8.0. My application includes dependency on Pulsar 2.7.2. It looks like these two have conflicts.

eolivelli commented 3 years ago

If you need to have 2.7.2 you have to use an older version of the jms client. Unfortunately Pulsar 2.8.0 has some internal breaking changes and it is not possible to support both of the major versions.

BTW you can use any version if the JMS client with any Pulsar with version >= 2.6.2 (if you are not using transactions, because in 2.8.0 the wire protocol changed regarding transactions, because in 2.7 they were still beta)