1

我在队列中有数百万条消息,前一千万条左右无关紧要。每条消息都有一个顺序的 ActionId,所以理想情况下< 10000000我可以忽略或更好地从队列中删除任何内容。到目前为止我所拥有的:

let azure = require("azure");

function processMessage(sb, message) {
    // Deserialize the JSON body into an object representing the ActionRecorded event
    var actionRecorded = JSON.parse(message.body);

    console.log(`processing id: ${actionRecorded.ActionId} from ${actionRecorded.ActionTaken.ActionTakenDate}`);

    if (actionRecorded.ActionId < 10000000) {
        // When done, delete the message from the queue
        console.log(`Deleting message: ${message.brokerProperties.MessageId} with ActionId: ${actionRecorded.ActionId}`);
        sb.deleteMessage(message, function(deleteError, response) {
            if (deleteError) {
                console.log("Error deleting message: " + message.brokerProperties.MessageId);
            }
        });
    }

    // immediately check for another message
    checkForMessages(sb);
}

function checkForMessages(sb) {
    // Checking for messages
    sb.receiveQueueMessage("my-queue-name", { isPeekLock: true }, function(receiveError, message) {
        if (receiveError && receiveError === "No messages to receive") {
            console.log("No messages left in queue");
            return;
        } else if (receiveError) {
            console.log("Receive error: " + receiveError);
        } else {
            processMessage(sb, message);
        }
    });
}

let connectionString = "Endpoint=sb://<myhub>.servicebus.windows.net/;SharedAccessKeyName=KEYNAME;SharedAccessKey=[mykey]"
let serviceBusService = azure.createServiceBusService(connectionString);

checkForMessages(serviceBusService);

我试过查看withFilter的文档,但它似乎不适用于队列。

除了上述操作之外,我无权创建或修改底层队列,因为队列是由客户端提供的。

我也可以吗

  • 过滤我从队列中获得的结果
  • 以某种方式加快队列处理?
4

1 回答 1

0

过滤我从队列中获得的结果

如您所见,过滤器作为一项功能仅适用于主题和订阅。

以某种方式加快队列处理

如果您要使用@azure/service-bus更新、更快的库来使用服务总线,您可以在 ReceiveAndDelete 模式下接收消息,直到您收到 ActionId 为 9999999 的消息,关闭该接收器,然后在 PeekLock 模式下创建一个新接收器。有关这些接收模式的更多信息,请参阅https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#settling-receive-operations

于 2020-12-22T07:06:25.410 回答