计时器触发器不会触发队列,但手动触发器会触发

编程入门 行业动态 更新时间:2024-10-11 11:14:03
本文介绍了计时器触发器不会触发队列,但手动触发器会触发-Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个队列触发器,当将消息手动添加到队列中时,它会启动并按预期运行.但是,通过以下计时器触发功能将消息写入队列时,它将无法启动.我可以看到该消息已被触发器成功写入.

I have a queue trigger which when message is manually added into queue it gets started and runs as expected. However, when message is written into queue by the following timer trigger function it fails to start. I can see the message is successfully written by the trigger.

** init .py **

** init.py**

import datetime import logging import os, uuid from azure.storage.queue import ( QueueClient, BinaryBase64EncodePolicy, BinaryBase64DecodePolicy ) import os, uuid import azure.functions as func def main(mytimer: func.TimerRequest) -> None: utc_timestamp = datetime.datetime.utcnow().replace( tzinfo=datetime.timezone.utc).isoformat() conn_str = os.environ['AzureWebJobsStorage'] queue_name="outqueue12" message = u"Hello234" queue_client = QueueClient.from_connection_string(conn_str, queue_name) # Setup Base64 encoding and decoding functions queue_client.message_encode_policy = BinaryBase64EncodePolicy() queue_client.message_decode_policy = BinaryBase64DecodePolicy() queue_client.send_message(message) logging.info('Python timer trigger function ran at %s', utc_timestamp)

host.json

{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[1.*, 2.0.0)" } }

有什么我想念的吗?

推荐答案

根据一些测试,该问题与base64编码有关.我添加了三行代码:

According to some test, the problem is related to base64 encode. I added three lines of code:

message_bytes = message.encode('ascii') base64_bytes = base64.b64encode(message_bytes) base64_message = base64_bytes.decode('ascii')

请参考以下整个功能代码:

Please refer to the whole function code below:

host.json

host.json

{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[1.*, 2.0.0)" } }

function.json

function.json

{ "scriptFile": "__init__.py", "bindings": [ { "name": "mytimer", "type": "timerTrigger", "direction": "in", "schedule": "*/20 * * * * *" } ] }

更多推荐

计时器触发器不会触发队列,但手动触发器会触发

本文发布于:2023-10-16 14:19:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   计时器   队列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!