Search code examples
javatomcat8ehcacheazureservicebusqpid

Problem connecting to Azure service bus using apache qpid-client


I am new to Azure service bus and apache qpid. I am trying to connect Azure service bus using AMPConnectionFactory in Tomcat context.xml as mentioned in https://qpid.apache.org/releases/qpid-jms-amqp-0-x-6.3.4/jms-amqp-0-8-book/JMS-Client-0-8-Appendix-Tomcat-JNDI-Integration.html and configure JMS peer cache replication

pom.xml

 <dependency>
            <groupId>org.apache.qpid</groupId>
            <artifactId>qpid-jms-client</artifactId>
            <version>0.47.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.qpid</groupId>
            <artifactId>qpid-client</artifactId>
            <version>6.3.4</version>
        </dependency>

Tomcat context.xml

    <Resource name="testConnectionFactory" auth="Container"
            type="org.apache.qpid.client.AMQConnectionFactory"
            factory="org.apache.qpid.jndi.ObjectFactory"
            connectionURL="amqp://rootmanagesharedaccesskey:*********=/? 
           brokerlist='servicebusurl:5672'"/>
   <Resource name="myqueue" auth="Container"
            type="org.apache.qpid.client.AMQQueue"
            factory="org.apache.qpid.jndi.ObjectFactory"
             address="BURL:direct://amq.direct//myqueue?durable='true'"/>`
    <Resource name="mytopic" auth="Container"
            type="org.apache.qpid.client.AMQTopic"
            factory="org.apache.qpid.client.AMQConnectionFactory"
            address="BURL:topic://amq.topic//mytopic?routingkey='mytopic'"/>

ehcache.xml

<cacheManagerPeerProviderFactory
    class="className extending JMSCacheManagerPeerProviderFactory"
    properties="initialContextFactoryName=org.apache.qpid.jms.jndi.JmsInitialContextFactory,
        replicationTopicConnectionFactoryBindingName=java:comp/env/testConnectionFactory,
        replicationTopicBindingName=java:comp/env/mytopic,
        getQueueConnectionFactoryBindingName=java:comp/env/testConnectionFactory,
        getQueueBindingName=java:comp/env/myqueue"
    propertySeparator="," />

className extending JMSCacheManagerPeerProviderFactory contains below code snippet. I cannot post complete class as its against policy

TopicConnectionFactory topicConnectionFactory;
topicConnectionFactory = (TopicConnectionFactory) context.lookup(replicationTopicConnectionFactoryBindingName);
replicationTopicConnection = topicConnectionFactory.createTopicConnection("username","password");

Above line of code is throwing exception. Am I missing any jar or incorrect version? When I debug , the socket connection to the azure service namespace is getting enabled but gets closed after waiting with below exception. Please advise

    Caused by: net.sf.ehcache.CacheException: Problem creating connections: Error creating connection: Protocol: 0.0 is required by the broker but is not currently supported by this client library implementation
    at com.distribution.jms.TestCacheManagerPeerProviderFactory.createCachePeerProvider(TestCacheManagerPeerProviderFactory.java:120)
    at net.sf.ehcache.config.ConfigurationHelper.createCachePeerProviders(ConfigurationHelper.java:136)
    at net.sf.ehcache.CacheManager.configure(CacheManager.java:795)
    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:471)
    at net.sf.ehcache.CacheManager.init(CacheManager.java:395)
    at net.sf.ehcache.CacheManager.<init>(CacheManager.java:270)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1116)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1092)
    at net.sf.ehcache.CacheManager.create(CacheManager.java:1075)
    at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:139)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
    ... 109 more
Caused by: javax.jms.JMSException: Error creating connection: Protocol: 0.0 is required by the broker but is not currently supported by this client library implementation
    at org.apache.qpid.client.AMQConnectionFactory.createConnection(AMQConnectionFactory.java:168)
    at org.apache.qpid.client.AMQConnectionFactory.createConnection(AMQConnectionFactory.java:143)
    at org.apache.qpid.client.AMQConnectionFactory.createTopicConnection(AMQConnectionFactory.java:195)
    at com.wwglobal.wits.distribution.jms.WITSJMSCacheManagerPeerProviderFactory.createCachePeerProvider(WITSJMSCacheManagerPeerProviderFactory.java:116)
    ... 120 more
Caused by: org.apache.qpid.AMQProtocolException: Protocol: 0.0 is required by the broker but is not currently supported by this client library implementation [error code: 543(client unsupported protocol)]
    at org.apache.qpid.client.AMQConnection.initDelegate(AMQConnection.java:715)
    at org.apache.qpid.client.AMQConnection.makeConnection(AMQConnection.java:600)
    at org.apache.qpid.client.AMQConnection.<init>(AMQConnection.java:522)
    at org.apache.qpid.client.AMQConnectionFactory.createConnection(AMQConnectionFactory.java:164)
    ... 123 more
Caused by: java.lang.ClassNotFoundException: org.apache.qpid.client.AMQConnectionDelegate_0_0
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1364)
    at org.apache.tomee.catalina.TomEEWebappClassLoader.loadClass(TomEEWebappClassLoader.java:208)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1185)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.apache.qpid.client.AMQConnection.initDelegate(AMQConnection.java:695)
    ... 126 more

Solution

  • Your first issue is that you have two different AMQP JMS clients included in your project:

    This one is an AMQP 1.0 based AMQP client and is actively being developed as AMQP 1.0 is the ISO standard AMQP protocol.

    <dependency>
        <groupId>org.apache.qpid</groupId>
        <artifactId>qpid-jms-client</artifactId>
        <version>0.47.0</version>
    </dependency>
    

    This one is the legacy AMQP 0.x JMS client and is not actively being developed, it received occasional bug fix releases as critical issues arise.

    <dependency>
        <groupId>org.apache.qpid</groupId>
        <artifactId>qpid-client</artifactId>
        <version>6.3.4</version>
    </dependency>
    

    So you need to choose one of these two, and since you are attempting to use Azure you should choose the first as Azure is an AMQP 1.0 based messaging system. So your second problem then is that you've configured tomcat to use the legacy client and Azure doesn't support a protocol that it can speak and so you get an error.