首页 \ 问答 \ sails.io.js - nodejs - Resourceful PubSub没有收到模型事件(sails.io.js - nodejs - Resourceful PubSub not receiving model events)

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);
    }
}

相关问答

更多
  • 您可以创建一个也实现IPay的包装类,并让它捕获所花费的时间。 public class PayWrapper : IPay { private readonly IPay _wrapped; public PayWrapper(IPay wrapped) { if (wrapped == null) throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; } ...
  • IronPython将始终使用BindGetMember ,然后调用结果,因为这就是Python的工作方式 - 从对象中获取属性,然后调用它。 您的BindGetMember实现应该返回另一个实现BindInvokeMember动态对象,它将具有您需要的参数。 IronPython will always use BindGetMember and then Invoke the result because that's how Python works - get the attribute from ...
  • 你在这里描述的基本上是活动记录模式或存储库模式之间的选择。 我建议您阅读这些模式并选择适合您的应用/体验/工具集的模式。 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 appl ...
  • 正如@GeorgeDuckett所说,T4模板可能是要走的路。 在我正在处理的应用程序中,我们使用它们很多,包括生成存储库,服务,ViewModel,枚举和最近的单元测试。 它们基本上是用VB或C#编写的代码生成脚本,查看XML文件的目录对于这些类型的模板都没有问题。 如果你确实选择了T4路线,那么有形T4编辑器绝对是必备的,它是免费下载的。 这是一个T4脚本的快速示例,该脚本应该或者非常接近您想要的: <#@ template language="C#" debug="true" hostspecific ...
  • 我知道你写过你不喜欢反思,但这真的很难看吗? var result = x.GetType().GetMethod( "MethodName" ).Invoke( x, new object[] { methodParams }); 如果方法可能重载,则不能仅按名称去,而是需要知道要调用它的参数数量。 像这样的东西 var method = x.GetType() .GetMethods() .First(m => m.Name == "Method ...
  • 您可以创建一个字典,其中练习编号为键,值为Action: class Program { static Dictionary exercises = new Dictionary { // put the numbers with the exercise method here: {1, () => Exercise1()}, {2, () => Exercise2()}, }; ...
  • 如果您有源,则可以使用正则表达式搜索this Type identifier 。 考虑到它必须是函数的第一个参数这样的事实应该做的伎俩: \(this:b+:i:b+:i 至少通过这种方式,您可以发现扩展方法的定义位置并添加该命名空间,然后依赖智能感知。 只是在一个非平凡的项目中运行它,其中包含大量的扩展方法,并且它起到了很大的作用。 唯一的误报是这样的: if(this is Blah... 我们可以通过在搜索中添加static来修复,因为扩展方法必须是静态的: static.*\(this:b+:i ...
  • 由Hans Passant提供,答案是使用正确的[ComVisible],[Guid]和[InterfaceType]属性来装饰接口。 Courtesy of Hans Passant, the answer is to decorate the interfaces with the correct [ComVisible], [Guid] and [InterfaceType] attributes.

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)