简体   繁体   English

我可以使用 node.js SDK 过滤 Azure ServiceBusService 吗?

[英]Can I filter an Azure ServiceBusService using node.js SDK?

I have millions of messages in a queue and the first ten million or so are irrelevant.我在队列中有数百万条消息,前一千万条左右无关紧要。 Each message has a sequential ActionId so ideally anything < 10000000 I can just ignore or better yet delete from the queue.每条消息都有一个连续的 ActionId,因此理想情况下,任何< 10000000我都可以忽略或更好地从队列中删除。 What I have so far:到目前为止我所拥有的:

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);

I've tried looking at the docs for withFilter but it doesn't seem like that applies to queues.我试过查看withFilter的文档,但似乎不适用于队列。

I don't have access to create or modify the underlying queue aside from the operations mentioned above since the queue is provided by a client.除了上面提到的操作之外,我无权创建或修改底层队列,因为队列是由客户端提供的。

Can I either我可以吗

  • Filter my results that I get from the queue过滤我从队列中获得的结果
  • speed up the queue processing somehow?以某种方式加速队列处理?

Filter my results that I get from the queue过滤我从队列中获得的结果

As you found, filters as a feature are only applicable to Topics & Subscriptions.如您所见,过滤器作为一项功能仅适用于主题和订阅。

speed up the queue processing somehow以某种方式加速队列处理

If you were to use the @azure/service-bus package which is the newer, faster library to work with Service Bus, you could receive the messages in ReceiveAndDelete mode until you reach the message with ActionId 9999999, close that receiver and then create a new receiver in PeekLock mode.如果您要使用@azure/service-bus包,它是与 Service Bus 一起工作的更新、更快的库,您可以在 ReceiveAndDelete 模式下接收消息,直到您到达带有 ActionId 9999999 的消息,关闭该接收器,然后创建一个PeekLock 模式下的新接收器。 For more on these receive modes, see https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#settling-receive-operations有关这些接收模式的更多信息,请参阅https://docs.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement#settling-receive-operations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM