使用apache qpid-client连接到Azure服务总线时出现问题

时间:2019-12-10 21:00:56

标签: java tomcat8 ehcache azureservicebus qpid

我是Azure Service Bus和apache qpid的新手。我正在尝试使用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中提到的在Tomcat context.xml中使用AMPConnectionFactory连接Azure服务总线,并配置JMS对等缓存复制

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="," />
扩展JMSCacheManagerPeerProviderFactory的

className包含以下代码片段。我无法按照政策发布完整的课程

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

上面的代码抛出异常。 我是否缺少任何jar版本或不正确的版本? 当我调试时,与azure服务名称空间的套接字连接已启用,但在等待以下异常后被关闭。请指教

    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

1 个答案:

答案 0 :(得分:0)

您的第一个问题是您的项目中包含两个不同的AMQP JMS客户端:

这是一个基于AMQP 1.0的AMQP客户端,由于AMQP 1.0是ISO标准AMQP协议,因此正在积极开发中。

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

这是旧版AMQP 0.x JMS客户端,尚未积极开发,由于出现严重问题,它偶尔会收到一些错误修复版本。

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

因此,您需要选择这两者之一,并且由于您尝试使用Azure,因此应该选择第一个,因为Azure是基于AMQP 1.0的邮件系统。因此,第二个问题是您已将tomcat配置为使用旧版客户端,而Azure不支持它可以说的协议,因此会出现错误。