在使用node.js特定延迟后从Azure ServiceBus主题发送消息
基本上,在Azure Service Bus中,我有一个主题和一个订阅.
Basically, within an Azure Service Bus, I have a topic and a subscription.
如果在11:00 AM之间有消息到达主题,则我的订户尚未处理该消息. 但是,在下午14:00,我希望我的订阅者可以对其进行处理.
If a message arrives in the topic between 11:00AM, my subscriber should not handle it yet. However, at 14:00PM, I would expect my subscriber to treat it.
是否有一种方法可以通过Topic过滤器本地实现?
Is there a way to achieve this natively with Topic filters?
我没有在有关过滤器的官方文档中提及这种用例.
实际上,所有提供的样本都与以下内容有关:
"订阅者处理这种消息,否则永远不会".
我在寻找:
"订户希望处理这种消息,但是稍后会在特定时间".
I don't find any mention of this kind of use case in the official documentation regarding filters.
Indeed, all presented samples are about:
"subscriber handling this kind of message, or never".
I'm looking for:
"subscriber expecting handling this kind of message but, but later at a specific time".
听起来像是您想推迟留言的声音?
Sounds like you want to defer a message ?
对 Azure SDK for Node.js 知之甚少,但是您可以设置 MSDN文档邮件上的ScheduledEnqueueTimeUtc
:
Don't know much about the Azure SDK for Node.js but from the MSDN Documentation you can set a ScheduledEnqueueTimeUtc
on the message :
UTC中计划的入队时间.此值用于延迟消息发送.它用于将邮件发送到将来的特定时间.
The scheduled enqueue time in UTC. This value is for delayed message sending. It is utilized to delay messages sending to a specific time in the future.
仅用于从nodejs sdk中,我找到了 constants.js 文件,用于定义以下属性:
From the nodejs sdk, I found a constants.js file that defines these properties :
/**
* The broker properties for service bus queue messages.
*
* @const
* @type {string}
*/
BROKER_PROPERTIES_HEADER: 'brokerproperties',
...
/**
* The scheduled enqueue time header.
*
* @const
* @type {string}
*/
SCHEDULED_ENQUEUE_TIME_HEADER: 'x-ms-scheduled-enqueue-time',
如果您查看 servicebusservice.js , setRequestHeaders
函数,该函数采用消息的某些属性并将其设置为标头.
If you have a look at the servicebusservice.js, there is a setRequestHeaders
function that takes some properties of the message and set it as header.
所以我想您可以在这样的消息上设置此属性:
So I guess you can set this property on the message like that :
// Set your scheduled date
var scheduledDate = Date.now();
scheduledDate.setHours(scheduledDate.getHours()+3);
var message = {
body: 'Test message',
brokerproperties: {
'x-ms-scheduled-enqueue-time': scheduledDate.toUTCString()
}};
让我知道它是否有效:-)
Let me know if it works :-)