iotedge:如何重新排队无法处理的消息 [英] iotedge: How to requeue message that could not be processed

查看:144
本文介绍了iotedge:如何重新排队无法处理的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Edge IoT设备上运行的publisherconsumer自定义模块.不管consumer模块是否对其进行处理,publisher模块都会以恒定的速率生成消息. consumer模块将消息发布到外部服务,并且由于没有Internet连接,consumer模块希望重新安排消息,以免丢失并再次尝试.

There are publisher and consumer custom modules that are running on an Edge IoT device. The publisher module keeps producing messages at constant rate no matter consumer module processes it or not. The consumer module POSTs the message to external service and given that there is no Internet connection, the consumer module would like to requeue the messsage so that is not lost and tried again.

我不喜欢写一个无限循环来保持重试;同样,如果模块重新启动,该消息也会丢失.所以我更喜欢将消息重新排队到edgeHub/RocksDB.

I do not prefer to write an infinite loop to keep retrying; also if the module is restarted the message would be lost. So i prefer to requeue the message to edgeHub/RocksDB.

在哪里可以找到有关可以为IoTHubMessageDispositionResult提供的可用响应的文档?如果需要重新排队消息,发送的响应是什么?

Where do I find documentation on available responses that can be provided for IoTHubMessageDispositionResult? what is the response to be sent if message needs to be requeued?

if message.processed():
    return IoTHubMessageDispositionResult.ACCEPTED
else:
    return IoTHubMessageDispositionResult.??

推荐答案

您不必实现自己的消息重新排队. IotEdge提供了此博客帖子,并在此文档页面.

You don't have to implement your own requeuing of messages. IotEdge provides offline functionality as described in this blog post and on this documentation page.

如果没有与IotHub的连接,则EdgeHub将在本地将消息存储在edgeDevice上.重新建立连接后,它将自动开始以正确的顺序发送这些消息.

The edgeHub will locally store messages on the edgeDevice if there is no connection to the IotHub. It will automatically start sending those messages (in the correct order) once the connection is established again.

您可以配置edgeHub将缓冲消息多长时间,如下所示:

You can configure how long edgeHub will buffer messages like this:

"$edgeHub": {
    "properties.desired": {
        "schemaVersion": "1.0",
        "routes": {},
        "storeAndForwardConfiguration": {
            "timeToLiveSecs": 7200
        }
    }
}

如果您未进行任何配置,则默认值为7200秒(2小时).

The 7200 seconds (2 hours) is also the default if you don't configure anything.

默认情况下,消息将被写入edgeHub docker容器内的文件夹中.如果要将它们存储在其他位置,则可以使用以下配置:

By default, the messages will be written to a folder within the edgeHub docker container. If you want to store them somewhere else you can do so with this configuration:

"edgeHub": {
    "type": "docker",
    "settings": {
        "image": "mcr.microsoft.com/azureiotedge-hub:1.0",
        "createOptions": {
            "HostConfig": {
                "Binds": ["<HostStoragePath>:<ModuleStoragePath>"],
                "PortBindings": {
                    "8883/tcp": [{"HostPort":"8883"}],
                    "443/tcp": [{"HostPort":"443"}],
                    "5671/tcp": [{"HostPort":"5671"}]
                }
            }
        }
    },
    "env": {
        "storageFolder": {
            "value": "<ModuleStoragePath>"
        }
    },
    "status": "running",
    "restartPolicy": "always"
}

用所需的值替换 HostStoragePath ModuleStoragePath .示例:

Replace HostStoragePath and ModuleStoragePath with the wanted values. Example:

"createOptions": {
                "HostConfig": {
                  "Binds": [
                    "/etc/iotedge/storage/:/iotedge/storage/"
                  ],
                  ...
                }
              }
            },
            "env": {
              "storageFolder": {
                "value": "/iotedge/storage/"
              },
              ...

请注意,您可能必须手动授予iotEdge用户(或所有用户)对该文件夹的访问权限(使用chmod).

Please note that you probably have to manually give the iotEdge user (or all users) access to that folder (using chmod).

更新:

如果您只是在寻找 IoTHubMessageDispositionResult 的可用值,则会找到答案

If you are just looking for the available values of IoTHubMessageDispositionResult you will find the answer here:

class IoTHubMessageDispositionResult(Enum):
    ACCEPTED = 0
    REJECTED = 1
    ABANDONED = 2

更新2:

已接受的邮件已从邮件队列中删除,因为它们已成功传递.

Messages that have been ACCEPTED are removed from the message queue because they have been successfully delivered.

已被已取消的消息再次添加到消息队列中,模块将尝试按照retryPolicy中的定义再次发送.有关retryPolicy的更多信息,您可以阅读此线程.

Messages that are ABANDONED are added to the message queue again and the module will try to send it again as defined in the retryPolicy. For more insight on the retryPolicy you can read this thread.

拒绝的邮件不会再次添加到邮件队列中.

Messages that are REJECTED are not added to the message queue again.

这篇关于iotedge:如何重新排队无法处理的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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