在使用node.js特定延迟后从Azure ServiceBus主题发送消息 [英] Send message from an Azure ServiceBus Topic after a specific delay with node.js

查看:90
本文介绍了在使用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 :-)

这篇关于在使用node.js特定延迟后从Azure ServiceBus主题发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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