订阅者在vue.js UI单个文件组件中

时间:2018-04-28 06:02:07

标签: javascript node.js vue.js

我正在尝试使用rabbitmq-pubsub

在vue.js中实现订阅者

然而,通过做

var Subscriber = require('rabbitmq-pubsub').Subscriber;

在终端我看到了

warning  in ./node_modules/_colors@1.0.3@colors/lib/colors.js

127:29-43 Critical dependency: the request of a dependency is an expression
浏览器控制台中的

是ee

"[WDS] Warnings while compiling."
"./node_modules/_colors@1.0.3@colors/lib/colors.js
127:29-43 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/_colors@1.0.3@colors/lib/colors.js
 @ ./node_modules/_colors@1.0.3@colors/safe.js
 @ ./node_modules/_winston@1.1.2@winston/lib/winston/config.js
 @ ./node_modules/_winston@1.1.2@winston/lib/winston.js
 @ ./node_modules/_logfilename@0.1.3@logfilename/src/logfilename.js
 @ ./node_modules/rabbitmq-pubsub/build/subscriber.js
 @ ./node_modules/rabbitmq-pubsub/build/index.js
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/SelectServices.vue
 @ ./src/components/SelectServices.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://10.9.1.147:8081 webpack/hot/dev-server ./src/main.js"

但是当我这样做时:

var subscriberOptions = {
  exchange: 'service_deployment_exchange',
  queueName: queue,
  url: amqpl_url
};

var subscriber = new Subscriber(subscriberOptions);
function onIncomingMessage(message) {
  debug('onIncomingMessage ', message.fields);
  console.log(message);

  subscriber.ack(message);

  //subscriber.nack(message);
};

但是当我在我的vue单个文件complonent的脚本元素中调用挂载函数中的下面一行时

subscriber.start(onIncomingMessage)

我得到了

TypeError: fs.readdirSync is not a function

除了仍显示在控制台中的警告旁边。

1 个答案:

答案 0 :(得分:0)

您无法在浏览器的代码中使用节点的api。我认为rabbitmq-pubsub是一个仅限节点的模块。