Http 触发器-Python-不断记录特定消息而不是 URL 正文或负载
Http Trigger-Python-Log Specific Message Constantly and not URL body or payload
基于之前的问题。下面的代码是一个httptrigger
,列出了对一个gis图层的编辑和更新。它将 url 负载登录到队列中。我不想加载有效载荷,而是加载特定的重复消息,以便每次都被覆盖,因为我不想时不时地出队。我该怎么做?
import logging
import azure.functions as func
def main(req: func.HttpRequest,msg: func.Out[str]) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
input_msg = req.params.get('message')
logging.info(input_msg)
msg.set(req.get_body())
return func.HttpResponse(
"This is a test.",
status_code=200
)
**function.json**
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "queue",
"direction": "out",
"name": "msg",
"queueName": "outqueue1",
"connection": "AzureStorageQueuesConnectionString"
}
]
}
I do not want the payload loaded but a specific repetitive message so
that it is overwritten everytime for I do not want to dequeue every
now and then.
不会,当你输入同一条消息时,它不会被覆盖。它刚刚在队列存储中排队。
如果要处理队列中的消息,使用queueclient或者使用azure函数的queuetrigger即可(queuetrigger函数基于queueclient,基本相同)
这是队列的 API 引用:
您可以使用它来处理队列中的消息,代码为 python。
这是azure function的queuetrigger:(已经集成,可以直接使用)
基于之前的问题。下面的代码是一个httptrigger
,列出了对一个gis图层的编辑和更新。它将 url 负载登录到队列中。我不想加载有效载荷,而是加载特定的重复消息,以便每次都被覆盖,因为我不想时不时地出队。我该怎么做?
import logging
import azure.functions as func
def main(req: func.HttpRequest,msg: func.Out[str]) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
input_msg = req.params.get('message')
logging.info(input_msg)
msg.set(req.get_body())
return func.HttpResponse(
"This is a test.",
status_code=200
)
**function.json**
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "queue",
"direction": "out",
"name": "msg",
"queueName": "outqueue1",
"connection": "AzureStorageQueuesConnectionString"
}
]
}
I do not want the payload loaded but a specific repetitive message so that it is overwritten everytime for I do not want to dequeue every now and then.
不会,当你输入同一条消息时,它不会被覆盖。它刚刚在队列存储中排队。
如果要处理队列中的消息,使用queueclient或者使用azure函数的queuetrigger即可(queuetrigger函数基于queueclient,基本相同)
这是队列的 API 引用:
您可以使用它来处理队列中的消息,代码为 python。
这是azure function的queuetrigger:(已经集成,可以直接使用)