0

我正在尝试使用此示例(https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-node-get-started-send),但我无法仅读取未读数据. 还有一件事我得到了两个不同的错误

1)连接ETIMEDOUT 40.112.242.0:5671

2) 更新检查点时租约丢失

在节点 js 示例中,我无法设置检查点。我也尝试过 Azure/azure-sdk-for-js。但它显示了上面列出的相同错误。

当我还运行 .netcore 示例时,它们工作正常,所以我不明白为什么节点 js 示例不能正常工作?

您能否指导我如何将此问题解决为只读未读数据和新数据?

4

1 回答 1

0

对于 node.js,请使用下面的代码设置检查点,它在我这边运行良好:

const { EventProcessorHost, delay } = require("@azure/event-processor-host");

//your eventhub name
const path = "myeventhub"; 

//your azure storage connection string
const storageCS = "DefaultEndpointsProtocol=https;AccountName=xx;AccountKey=xx;EndpointSuffix=core.windows.net";

//your eventhub namespace connectionstring 
const ehCS = "Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xxx"

//your blob storage container name
const storageContainerName = "test6";

async function main() {
  // Create the Event Processo Host
  const eph = EventProcessorHost.createFromConnectionString(
    EventProcessorHost.createHostName("my-host"),
    storageCS,
    storageContainerName,
    ehCS,
    {
      eventHubPath: path
    }

  );
  let count = 0;
  // Message event handler
  const onMessage = async (context/*PartitionContext*/, data /*EventData*/) => {
    console.log(">>>>> Rx message from '%s': '%s'", context.partitionId, data.body);
    count++;

    return await context.checkpoint();
  };
  // Error event handler
  const onError = (error) => {
    console.log(">>>>> Received Error: %O", error);
  };
  // start the EPH
  await eph.start(onMessage, onError);
  // After some time let' say 2 minutes
  await delay(120000);
  // This will stop the EPH.
  await eph.stop();
}

main().catch((err) => {
  console.log(err);
});

我可以看到检查点在 blob 容器中设置正确:

在此处输入图像描述

于 2019-10-24T06:56:45.273 回答