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
2022-11-27 19:11

满意答案

您可以创建一个也实现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#)

您可以创建一个也实现IPay的包装类,并让它捕获所花费的时间。 public class PayWrapper : IPay { private readonly IPay _wrapped; public PayWrapper(IPay wrapped) { if (wrapped == null) throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; ...

拦截方法调用c#对象(Intercepting method invocation to c# objects)

IronPython将始终使用BindGetMember ,然后调用结果,因为这就是Python的工作方式 - 从对象中获取属性,然后调用它。 您的BindGetMember实现应该返回另一个实现BindInvokeMember动态对象,它将具有您需要的参数。 IronPython will always use BindGetMember and then Invoke the result because that's how Python works - get the attribute ...

C#类和方法(C# classes and methods)

你在这里描述的基本上是活动记录模式或存储库模式之间的选择。 我建议您阅读这些模式并选择适合您的应用/体验/工具集的模式。 What you are describing here is basically a choice between the Active Record Pattern or the Repository Pattern. I'd advise you to read up on those patterns and choose whichever one fits your...

在设计或构建时生成方法(C#)(Generating methods in design or in build time (C#))

正如@GeorgeDuckett所说,T4模板可能是要走的路。 在我正在处理的应用程序中,我们使用它们很多,包括生成存储库,服务,ViewModel,枚举和最近的单元测试。 它们基本上是用VB或C#编写的代码生成脚本,查看XML文件的目录对于这些类型的模板都没有问题。 如果你确实选择了T4路线,那么有形T4编辑器绝对是必备的,它是免费下载的。 这是一个T4脚本的快速示例,该脚本应该或者非常接近您想要的: <#@ template language="C#" debug="true" hostspe...

C#非常动态的调用(C# very dynamic invocation)

我知道你写过你不喜欢反思,但这真的很难看吗? var result = x.GetType().GetMethod( "MethodName" ).Invoke( x, new object[] { methodParams }); 如果方法可能重载,则不能仅按名称去,而是需要知道要调用它的参数数量。 像这样的东西 var method = x.GetType() .GetMethods() .First(m => m.Name == "M...

c#中方法的菜单(Menu for methods in c#)

您可以创建一个字典,其中练习编号为键,值为Action: class Program { static Dictionary<int, Action> exercises = new Dictionary<int, Action> { // put the numbers with the exercise method here: {1, () => Exercise1()}, {2, () => Exercise2()}, ...

C#:发现扩展方法(C#: Discovering Extension Methods)

如果您有源,则可以使用正则表达式搜索this Type identifier 。 考虑到它必须是函数的第一个参数这样的事实应该做的伎俩: \(this:b+:i:b+:i 至少通过这种方式,您可以发现扩展方法的定义位置并添加该命名空间,然后依赖智能感知。 只是在一个非平凡的项目中运行它,其中包含大量的扩展方法,并且它起到了很大的作用。 唯一的误报是这样的: if(this is Blah... 我们可以通过在搜索中添加static来修复,因为扩展方法必须是静态的: static.*\(this...

将C ++ COM类转换为C#以供C ++可执行文件调用(Convert C++ COM class to C# for invocation by C++ executable)

由Hans Passant提供,答案是使用正确的[ComVisible],[Guid]和[InterfaceType]属性来装饰接口。 Courtesy of Hans Passant, the answer is to decorate the interfaces with the correct [ComVisible], [Guid] and [InterfaceType] attributes.

相关文章

更多

NodeJS系列-部署

NodeJS我就不介绍了,被标题吸引进来的人可以看这个链接,了解NodeJS。下来就开始关于NodeJ ...

nodejs与html代码分离

有没有什么办法不用框架就可以让html和js代码分离,每写一句html都要用引号和加号忒麻烦. 怎样 ...

微信公众平台NodeJs开发之路--消息处理

悲剧!写了半小时的博文,没有自动保存的功能,手冻僵了,具体过程不写了,有问题给我留言吧!杭州的冬天太冷 ...

微信公众平台NodeJs开发之路--接入认证

微信公众平台已经开启了一段时间了,一直不知道怎么申请接入,最近在网上看到有一哥们成功的做了一个可以返回 ...

顶 【CF 应用开发大赛】WeBot - 微信公众平台消息接口类库(nodejs)

应用名称:WeBot -微信公众平台提供的开放信息接口的自动回复系统,基于node.js实现。 创新 ...

HTML5服务器事件发送(Server-Sent Events)【HTML5教程 - 第十三篇】

erver-Sent Events - 单向的信息处理.一个SSE(server send event ...

nodejs开发的个人网页收藏搜索网站,界面有些糟糕

优克斯youkes.com(推荐chrome浏览器,现阶段仅用该浏览器进行了目测) 请注意:每日23: ...

微信XML消息model定义之微信公众平台(一)

很简单的model定义。 packagecn.wx.server;importorg.dom4j.Do ...

Java 流(Stream)、文件(File)和IO

Java 流(Stream)、文件(File)和IO Java.io包几乎包含了所有操作输入、输 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本