【问题标题】:How to receive messages from dead letter queue from azure service bus queue如何从 Azure 服务总线队列接收死信队列的消息
【发布时间】:2017-02-13 01:20:06
【问题描述】:

我有一个队列,当我向该队列发送消息时,我看到大部分消息都进入了它的死信队列。我想将它们重新提交到同一个队列..
如果有人可以建议我任何解决方案,那对我非常有帮助。

【问题讨论】:

标签: azure azure-functions azure-queues


【解决方案1】:

一种可能的方法是从死信队列接收消息并将它们发送到普通队列。

Python 代码

第一步:从死信队列接收消息:

from azure.servicebus import ServiceBusClient
import json
connectionString = "Your Connection String to Service Bus"
serviceBusClient = ServiceBusClient.from_connection_string(connectionString)
queueName = "Your Queue Name created in the Service Bus"
queueClient = serviceBusClient.get_queue(queueName)
with queueClient.get_deadletter_receiver(prefetch=5) as queueReceiver:
messages = queueReceiver.fetch_next(timeout=100)
for message in messages:
    # message.body is a generator object. Use next() to get the body.
    body = next(message.body)
    # Store the body in some list so that we can send them to normal queue.
    message.complete()

第 2 步:将消息发送到普通队列:

from azure.servicebus import ServiceBusClient, Message
connectionString = "Your Service Bus Connection String"
serviceBusClient = ServiceBusClient.from_connection_string(connectionString)
queueName = "Your Queue name"
queueClient = serviceBusClient.get_queue(queueName)

messagesToSend = [<List of Messages that we got from the dead letter queue>]

with queueClient.get_sender() as sender:
    for msg in messagesToSend:
        sender.send(Message(msg))

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-01
    • 2017-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多