user3400763
user3400763

Reputation: 1

Unable to set checkpoint in partition

I am trying to use this sample (https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-node-get-started-send) but I am not able to read unread data only. One more thing I am getting two different error

1) connect ETIMEDOUT 40.112.242.0:5671

2) lease lost while updating checkpoint

In the node js sample, I am not able to set checkpoints. I have tried Azure/azure-sdk-for-js as well. But it is showing the same error listed above.

When I have also run .netcore sample then they are working fine so I am not getting why node js sample is not working fine?

Can you please guide me on how can fix this issue to read-only unread and new data?

Upvotes: 0

Views: 688

Answers (1)

Ivan Glasenberg
Ivan Glasenberg

Reputation: 30035

For node.js, please use the code below to set checkpoint, it works well at my side:

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);
});

And I can see the checkpoint is set correctly in blob container:

enter image description here

Upvotes: 0

Related Questions