sails.io.js - nodejs - Resourceful PubSub没有收到模型事件(sails.io.js - nodejs - Resourceful PubSub not receiving model events)
我正在尝试订阅一个nodejs应用程序来模拟sails中的事件。 这是我的代码:
var socketIOClient = require('socket.io-client'), sailsIOClient = require('sails.io.js'); var io = sailsIOClient(socketIOClient); io.sails.url = 'http://localhost:1337'; io.socket.on("agent", function(event) { console.log(event); }) io.socket.get("/agent", function(resData, jwres) {})
当客户端(nodejs)连接时,以下是sails服务器上所有输出的链接:
https://gist.github.com/CiscoKidxx/e5af93ebcc24702ba4f8
我的理解是,当我创建一个新的代理时,它应该触发一个列出更改的console.log(event)。 这没有发生。 脚本启动后,我确实收到了“现在已连接到风帆”。 有什么想法吗?
这里是我的电话在我的UserController中创建一个新的代理:
Agent.create({ syncToken: token, owner: user.id }).exec(function (err, newAgent) { Agent.publishUpdate(newAgent.id, {syncToken: newAgent.syncToken});
I am trying to subscribe a nodejs application to model events in sails. Here is my code:
var socketIOClient = require('socket.io-client'), sailsIOClient = require('sails.io.js'); var io = sailsIOClient(socketIOClient); io.sails.url = 'http://localhost:1337'; io.socket.on("agent", function(event) { console.log(event); }) io.socket.get("/agent", function(resData, jwres) {})
Here is a link to all of the output on the sails server when the client(nodejs) connects:
https://gist.github.com/CiscoKidxx/e5af93ebcc24702ba4f8
My understanding is that when I create a new agent it should trigger a console.log(event) which lists the changes. This is not happening. I do get a "now connected to sails" upon script start up. Any thoughts?
Here is my call to create a new agent in my UserController:
Agent.create({ syncToken: token, owner: user.id }).exec(function (err, newAgent) { Agent.publishUpdate(newAgent.id, {syncToken: newAgent.syncToken});
原文:https://stackoverflow.com/questions/33926792
满意答案
您可以创建一个也实现IPay的包装类,并让它捕获所花费的时间。
public class PayWrapper : IPay { private readonly IPay _wrapped; public PayWrapper(IPay wrapped) { if (wrapped == null) throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; } public void DecreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.DecreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } public void IncreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.IncreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } }
然后当一个类得到一个IPay时,它可以像这样使用包装器:
public class ConsumerOfPay { private IPay _pay; public ConsumerOfPay(IPay pay) { _pay = new PayWrapper(pay); } }
You could create a wrapper class that also implements IPay and have it capture the amount of time it took.
public class PayWrapper : IPay { private readonly IPay _wrapped; public PayWrapper(IPay wrapped) { if (wrapped == null) throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; } public void DecreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.DecreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } public void IncreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.IncreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } }
Then when a class gets an IPay, it can use the wrapper like this:
public class ConsumerOfPay { private IPay _pay; public ConsumerOfPay(IPay pay) { _pay = new PayWrapper(pay); } }
相关问答
更多实现一个类来查找C#中方法的调用时间(Implement a class to find invocation time of methods in C#)
拦截方法调用c#对象(Intercepting method invocation to c# objects)
C#类和方法(C# classes and methods)
在设计或构建时生成方法(C#)(Generating methods in design or in build time (C#))
C#非常动态的调用(C# very dynamic invocation)
c#中方法的菜单(Menu for methods in c#)
C#:发现扩展方法(C#: Discovering Extension Methods)
将C ++ COM类转换为C#以供C ++可执行文件调用(Convert C++ COM class to C# for invocation by C++ executable)
相关文章
更多NodeJS系列-部署
nodejs与html代码分离
微信公众平台NodeJs开发之路--消息处理
微信公众平台NodeJs开发之路--接入认证
顶 【CF 应用开发大赛】WeBot - 微信公众平台消息接口类库(nodejs)
《MLDN出品 魔乐科技Node.JS + MongoDB(JSP、HTML 、XML、JavaScript、Servlet、Struts、Ajax)视频汇总》(Node.JS + MongoDB\JSP、HTML 、XML、JavaScript、Servlet、Struts、Ajax nodejs)V2013[压缩包]
HTML5服务器事件发送(Server-Sent Events)【HTML5教程 - 第十三篇】
nodejs开发的个人网页收藏搜索网站,界面有些糟糕
微信XML消息model定义之微信公众平台(一)
Java 流(Stream)、文件(File)和IO
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!