NodeJs EventHubClient->接收器问题 [英] NodeJs EventHubClient --> Receiver problem

查看:75
本文介绍了NodeJs EventHubClient->接收器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我希望有人对这个问题有一个答案


问题描述:

我遵循了入门"使用nodejs读取/接收eventhub上的事件的Azure指令.

https://docs.microsoft.com/zh-cn/azure/iot-hub/quickstart-send-telemetry-node#read-the-telemetry-from-your-hub

我下载了ReadDeviceToCloudMessage.js脚本

如果我在shell中使用nodejs执行该脚本,我将收到从设备到云的消息

消息由我手动触发,并且是异步的.

开始时,脚本正在运行,并且可以接收所有消息.但是,如果从设备发送消息之间的间隔较长(〜2分钟),则脚本将无法正常工作,因此尽管 没有错误或警告.

似乎接收方有超时或类似的超时时间,但是没有日志,所以我无法确认

解决方法:

现在,我已经通过发送将被丢弃在云端的虚拟消息来解决此问题.

此虚拟消息是同步的,似乎此同步消息使接收者保持活动状态.

有人想以更好的方式解决这个问题吗?

谢谢

基督徒


解决方案

你好 您遵循的本教程未针对连续接收事件进行优化.

让我指向 azure-event-hubs-node github存储库,您可以在其中查找有关如何连续高速接收事件/消息的示例.

来自 这里:

接收事件

有两种方法可以使用EventHub Client接收事件.

流式接收器

The  client.receive(. . .) 方法.该消息采用 errorHandler()以及其他参数,并将其注册到接收器. 此方法返回等待receiveHandler.stop() 这种机制在场景中非常有用, 您想连续不断地高速接收事件/消息的地方.

分批接收器

您可以使用

如果此答案有帮助,请单击标记为答案"或投票.要提供有关您的论坛体验的其他反馈,请单击 /p>




Hi all,

I hope somebody has an answer for this issue


Problem description:

I followed a "getting started" instruction of azure using nodejs to read/receive events on a eventhub.

https://docs.microsoft.com/en-us/azure/iot-hub/quickstart-send-telemetry-node#read-the-telemetry-from-your-hub

I downloaded the ReadDeviceToCloudMessage.js script

If I execute that script in the shell with nodejs I will receive messages coming from the device to the cloud

The messages are triggered manually by me and are asynchronous.

At the beginning the script is working and all messages can be received. But if there is a longer pause between sending the messages from device (~2 minutes) the script isn't working properly anymore and therefore the messages can't be received although there is no error or warning.

It seems like that the receiver has a timeout or something like that, but there is no log so i can't confirm that

Workaround:

Now I've done a workaround by sending dummy messages which will be thrown away on the cloud side.

This dummy messages are synchronous and it seems that this synchronous messages keep the reciever alive.

Has somebody an idea to solve this issue in a better way ???

Thank you

Christian


解决方案

Hello Code-Predator thank you for your feedback!

I believe that this tutorial that you followed is not optimized to continuously receive events.

Let me point to the azure-event-hubs-node github repo where you can find examples on how to continuously receive events/messages at a high speed.

From here:

Receiving events

There are two ways to receive events using the EventHub Client.

Streaming receiver

The EventHubClient has a client.receive(. . .) method on the receiver. This message takes the messageHandler() and the errorHandler() amongst other parameters and registers them to the receiver. This method returns a ReceiverHandler that can be used to stop receiving further events await receiverHandler.stop() This mechanism can be useful in a scenario, where you want to continuously receive events/messages at a high speed.

Batching receiver

You can use await client.receiveBatch(...) to receive desired number of events for specified amount of time. It will return an array of EventData objects once it receives the desired number of events or the max wait time occurs (which ever happens first). This mechanism can be useful when you want to receive events/messages in a batch. If your in a scenario where you would like to receive some messages and process them (since message processing is time consuming), and later get some more messages, then this mechanism will suite your needs better.

==========================================================

If this answer was helpful, click "Mark as Answer" or Up-Vote. To provide additional feedback on your forum experience, click here




这篇关于NodeJs EventHubClient->接收器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆