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

Problem connecting to Azure service bus using apache qpid-client

我是 Azure 服务总线和 apache qpid 的新手。我正在尝试使用 Tomcat context.xml 中的 AMPConnectionFactory 连接 Azure 服务总线,如 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 中所述,并配置 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="," />

class扩展 JMSCacheManagerPeerProviderFactory 的名称包含以下代码片段。我无法 post 完成 class 因为它违反政策

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

您的第一个问题是您的项目中包含两个不同的 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 不支持它可以使用的协议,因此您会收到错误消息。