简体   繁体   English

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

[英]how to keep azure event hub connection alive for receiving batch diagnostic using amqp

We had enabled diagnostic feature on our batch account to stream events to event hub which we are capturing in our application to take action based on batch task states. 我们在批处理帐户上启用了诊断功能,以便将事件流式传输到我们在应用程序中捕获的事件中心,以便根据批处理任务状态执行操作。 However we are noticing that the connection gets closed automatically(probably because no events occurring over night) and hence we have to bounce back the server every once in a while to receive the events/messages back again. 但是我们注意到连接自动关闭(可能是因为没有事件发生在夜间)因此我们不得不每隔一段时间就恢复服务器以再次接收事件/消息。

We still rely on java 7 and here are the dependencies that we added for batch processing: 我们仍然依赖于java 7,这里是我们为批处理添加的依赖项:

       //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

And here is the code snipped that does the connection, actually we used the code example given here : http://theitjourney.blogspot.com/2015/12/sendreceive-messages-using-amqp-in-java.html since we couldn't find any working example for java 7 in azure doc itself. 以下是执行连接的代码剪切,实际上我们使用了此处给出的代码示例: http//theitjourney.blogspot.com/2015/12/sendreceive-messages-using-amqp-in-java.html因为我们无法在azure doc本身找不到java 7的任何工作示例。

     /**
     * 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
    }

So is there a way to track if a connection was closed, and if so re-start the connection again? 那么有没有办法跟踪连接是否已关闭,如果是,请重新启动连接?
Any information to further diagnose this issue will be appreciated as well. 任何进一步诊断此问题的信息也将受到赞赏。

I think I found the issue, I had used "SBCFR" as connectionFactoryName, looking closely at the example in the link, I should have used "SBCF". 我想我发现了这个问题,我使用了“SBCFR”作为connectionFactoryName,仔细查看链接中的示例,我应该使用“SBCF”。 Also I updated the lib "org.apache.qpid:qpid-jms-client" from version "0.40.0" to "0.41.0" 我还将lib“org.apache.qpid:qpid-jms-client”从版本“0.40.0”更新为“0.41.0”

Also in the above code, I shouldn't have used AUTO_ACKNOWLEGDE because for the longest time I thought something was wrong because I was never receiving the events in my local setup. 同样在上面的代码中,我不应该使用AUTO_ACKNOWLEGDE因为最长时间我认为有些错误,因为我从未在本地设置中接收事件。 Turned out other machines were also connected to the same consumer group and had already ack'ed the message. 原来其他机器也连接到同一个消费者群体,并且已经收到了消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM