如何轮询azure服务总线队列中的消息? [英] How to poll the azure service bus queue for messages?

查看:119
本文介绍了如何轮询azure服务总线队列中的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何轮询azure服务总线以连续检查消息?这是我从队列中接收消息的方式.

How do I poll the azure service bus to continuously check for the messages? Here is how I receive the message from the queue.

   from azure.servicebus import QueueClient

   client = QueueClient.from_connection_string(
       q_string,
       q_name)

   msg = None

   with client.get_receiver() as queue_receiver:
     messages = queue_receiver.fetch_next(max_batch_size=1, timeout=3)
     if len(messages) > 0:
        msg = messages[0]
        print(f"Received {msg.message}")

  return msg

我要不断寻找消息,然后对其进行处理.

I want to continuously look for the message and then process it.

推荐答案

正如George chen所说,我认为服务总线队列触发器符合您的要求.

As George chen says, I think service bus queue trigger meets your requirement.

_init_.py:

_init_.py:

import logging

import azure.functions as func


def main(msg: func.ServiceBusMessage):
    logging.info('Python ServiceBus queue trigger processed message: %s',
                 msg.get_body().decode('utf-8'))


function.json:


function.json:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "msg",
      "type": "serviceBusTrigger",
      "direction": "in",
      "queueName": "test",
      "connection": "str"
    }
  ]
}


env var:


env var:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=lti/ThmF+mw9BebOacp9gVazIh76Q39ecikHSCkaTcGK5hmInspX+EkjzpNmvCPWsnvapWziHQHL+kKt2V+lZw==;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "str": "Endpoint=sb://bowmantest.servicebus.xxxxxxx"
  }
}

如果是天蓝色,则环境变量是在配置设置上,而不是local.settings.json.

If on azure, the env var is on configuration settings instead of local.settings.json.

执行此操作时,触发器将帮助您捕获服务总线队列中的信息.(立即)

When you do this, the trigger will help you to capture the information in the service bus queue.(instant)

这篇关于如何轮询azure服务总线队列中的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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