首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用amqp保持azure事件集线器连接的活动状态以接收批量诊断

如何使用amqp保持azure事件集线器连接的活动状态以接收批量诊断
EN

Stack Overflow用户
提问于 2019-04-23 22:06:54
回答 1查看 260关注 0票数 0

我们已经在我们的batch账户上启用了诊断功能,以将事件流式传输到我们在应用程序中捕获的event hub,以便基于batch任务状态采取行动。然而,我们注意到连接会自动关闭(可能是因为晚上没有事件发生),因此我们必须每隔一段时间重新启动服务器,才能再次接收事件/消息。

我们仍然依赖于java 7,下面是我们为批处理添加的依赖项:

代码语言:javascript
复制
       //azure dependency
        compile('com.microsoft.azure:azure-storage:7.0.0')
        compile('com.microsoft.azure:azure-batch:5.0.1') {
            //do not get transitive dependency com.nimbusds:nimbus-jose-jw because spring security still rely on old version of it
            excludes group: 'com.nimbusds', module: 'nimbus-jose-jw'
        }
        compile('com.fasterxml.jackson.core:jackson-core:2.9.8')
        compile('org.apache.qpid:qpid-amqp-1-0-common:0.32')
        compile('org.apache.qpid:qpid-amqp-1-0-client:0.32')
        compile('org.apache.qpid:qpid-amqp-1-0-client-jms:0.32')
        compile('org.apache.qpid:qpid-jms-client:0.40.0')
        compile('org.apache.geronimo.specs:geronimo-jms_1.1_spec:1.1.1')
        //end of azure dependency

这是进行连接的代码片段,实际上我们使用了这里给出的代码示例:http://theitjourney.blogspot.com/2015/12/sendreceive-messages-using-amqp-in-java.html,因为我们在azure文档本身中找不到任何适用于java7的示例。

代码语言:javascript
复制
     /**
     * Set up connection to the service bus using AMQP mechanism.
     * NOTE: Messages received from the message bus are not guaranteed to follow order.
     * */
    MessageConsumer initiateConsumer(MessageListener messageListener, Integer partitionInx, BatchEventHubConfig batchEventHubConfig) {
        // set up JNDI context
        String queueName = "EventHub"
        String connectionFactoryName = "SBCFR"

        Hashtable<String, String> hashtable = new Hashtable<>()
        hashtable.put("connectionfactory.${connectionFactoryName}", batchEventHubConfig.getAMQPConnectionURI())
        hashtable.put("queue.${queueName}", "${batchEventHubConfig.name}/ConsumerGroups/${batchEventHubConfig.consumerGroup}/Partitions/${partitionInx}")
        hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory")
        Context context = new InitialContext(hashtable)

        ConnectionFactory factory = (ConnectionFactory) context.lookup(connectionFactoryName)
        Destination queue = (Destination) context.lookup(queueName)
        Connection connection = factory.createConnection(batchEventHubConfig.sasPolicyName, batchEventHubConfig.sasPolicyKey)
        connection.setExceptionListener(new BatchExceptionListener())

        connection.start()
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
        MessageConsumer messageConsumer = session.createConsumer(queue)
        messageConsumer.setMessageListener(messageListener)
        messageConsumer
    }

那么,是否有一种方法可以跟踪连接是否关闭,如果是,是否可以重新启动连接?

任何进一步诊断此问题的信息也将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2019-04-24 19:36:34

我想我找到了问题所在,我使用了"SBCFR“作为connectionFactoryName,仔细观察链接中的示例,我应该使用"SBCF”。我还将lib "org.apache.qpid:qpid-jms-client“从版本"0.40.0”更新为"0.41.0“。

另外,在上面的代码中,我不应该使用AUTO_ACKNOWLEGDE,因为在很长一段时间内,我都认为出了问题,因为我从未在本地设置中接收到事件。事实证明,其他机器也连接到相同的消费者组,并且已经确认了消息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55813135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档