Senecajs和RabbitMQ ...'amqp'运输无法完全正常工作

时间:2019-11-23 11:56:41

标签: rabbitmq seneca

我有一个简单的Senecajs和RabbitMQ设置。

监听器

// foo.js (listener)
var seneca = require('seneca')();

seneca
  .use('seneca-amqp-transport')
  .add({
    "role": "foo",
    "cmd": "ping"
  }, (args, done) => {
     done(null, { result: "Hi FOO" });
  })
  .listen({
    type: 'amqp',
    pin: 'cmd:ping',
    url: 'amqp://guest:guest@localhost:5672'
  });// default - 10101 

客户

// app.js (client)

var seneca = require('seneca');

var foo = seneca()
  .use('seneca-amqp-transport')
  .client({
    type: 'amqp',
    pin: 'role:foo,cmd:ping',
    url: "amqp://guest:guest@localhost:5672"
  })
  .act('role:foo,cmd:ping', { message: 'Aha!' }, (err, response) => {
    if (err) console.error(err);
    else console.log(response);
  });

package.json

 ...
 "dependencies": {
    "seneca": "^3.17.0",
    "seneca-amqp-transport": "^2.2.0"
 }
...

当我运行这两个文件(节点foo.js然后是节点app.js)时,app.js引发以下错误:


 code: 'act_execute',
  seneca: true,
  package: 'seneca',
  msg:
   'seneca: Action cmd:ping,role:foo failed: Cannot read 
property \'pattern\' of undefined.',
  details:
   { message: 'Cannot read property \'pattern\' of undefined',
     pattern: 'cmd:ping,role:foo',
     fn:
      { [Function: transport_client]
        id:
         'pg:cmd:ping,role:foo,pin:role:foo,cmd:ping,type:amqp,url:amqp://guest:guest@0.0.0.0:5672' },
     callback: [Function],
     instance: 'Seneca/hhdy5dxvtas8/1574507599580/4684/3.17.0/-',
     callpoint: undefined,
     'orig$':
      TypeError: Cannot read property 'pattern' of undefined

但是,我可以清楚地看到(在RabbitMQ仪表板中)那些连接已建立...

这是我第一次与Senecajs和RabbitMQ玩...我做错了什么?

1 个答案:

答案 0 :(得分:0)

似乎将var“ {legacy:{meta:true}}”添加到Seneca initializator可以解决此问题...

var seneca = require('seneca')({legacy: {meta:true}});