node.js中怎么对CQS进行操作-创新互联

本篇文章为大家展示了node.js中怎么对CQS进行操作,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

创新互联专注于企业成都全网营销、网站重做改版、阿城网站定制设计、自适应品牌网站建设、H5技术成都做商城网站、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为阿城等各大城市提供网站开发制作服务。

怎样使用node.js来操作CQS

安装:

$npminstallcqs

初始化你的CQS模块:

//Anormalimport.

varcqs=require('cqs');

//Pre-applymycouchanddbname.

cqs=cqs.defaults({"couch":"https://user:password@example.iriscouch.com"

,"db":"cqs_queue"

});

列出所有的队列:

cqs.ListQueues(function(error,queues){

console.log("Found"+queues.length+"queues:");

queues.forEach(function(queue){

console.log("*"+queue.name);

})

//Output:

//Found2queues:

//*a_queue

//*another_queue

})

创建一个队列:

//Justcreatewithaname.

cqs.CreateQueue("important_stuff",function(error,queue){

if(!error)

console.log("Importantstuffqueueisready");

})

//Createwithanoptionsobject.

varopts={QueueName:"unimportant_stuff"

,DefaultVisibilityTimeout:3600//1hour

};

cqs.CreateQueue(opts,function(error,queue){

if(!error)

console.log("Created"+queue.name+"withtimeout+"queue.VisibilityTimeout);

//Output

//Createdunimportant_stuffwithtimeout3600

})

怎样使用node.js来操作CQS

添加一个队列消息:

//TheconvenientobjectAPI:

important_stuff.send(["keepthese","things","inorder"],function(error,message){

if(!error)

console.log('Sent:'+JSON.stringify(message.Body));

//Output:

//Sent:["keepthese","things","inorder"]

})

cqs.SendMessage(important_stuff,"Thismessageisimportant!",function(error,message){

if(!error)

console.log('Sentmessage:'+message.Body);

//Output:

//Sentmessage:Thismessageisimportant!

})

//Or,justusethequeuename.

cqs.SendMessage('some_other_queue',{going_to:"theotherqueue"},function(error,message){

if(!error)

console.log('Message'+message.MessageId+'isgoingto'+message.Body.going_to);

//Output:

//Messagea9b1c48bd6ae433eb7879013332cd3cdisgoingtotheotherqueue

})

接收并处理一条队列消息:

//TheconvenientobjectAPI:

my_queue.receive(function(error,messages){

if(!error)

console.log('Receivedmessage:'+JSON.stringify(messages[0].Body));

//Output:

//Receivedmessage:

})

//ThestandardAPI,receivingmultiplemessages

cqs.ReceiveMessage(some_queue,5,function(er,messages){

if(!error)

console.log('Received'+messages.length+'messages');

//Output:

//Received<0through6>messages

})

删除一条队列消息:

//TheconvenientobjectAPI:

message.del(function(error){

//Messagedeletionneverresultsinanerror.Ifamessageissuccessfully

//deleted,itwillsimplyneverappearinthequeueagain.

console.log('Messagedeleted!');

})

//ThestandardAPI:

cqs.DeleteMessage(my_message,function(error){

console.log('Messagedeleted');

})

上述内容就是node.js中怎么对CQS进行操作,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。

新闻标题:node.js中怎么对CQS进行操作-创新互联
本文链接:https://www.cdcxhl.com/article16/doscdg.html

成都网站建设公司_创新互联,为您提供建站公司响应式网站企业网站制作微信公众号做网站品牌网站制作

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都seo排名网站优化