javascript - vue.js UI 单文件组件中的订阅者
问题描述
我正在尝试使用在 vue.js 中实现订阅者rabbitmq-pubsub
,
然而,通过做
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 单个文件组件的脚本元素中的挂载函数中调用以下行时
subscriber.start(onIncomingMessage)
我明白了
TypeError: fs.readdirSync is not a function
除了警告仍然出现在控制台中。
解决方案
您不能在浏览器代码中使用节点的 api。而且我认为 rabbitmq-pubsub 是一个仅限节点的模块。
推荐阅读
- python - 试图抓取 Lazada 产品页面
- c++ - 为什么 cout << *lkop[4] 的输出是 0?
- azure-devops - DevOps 工作项创建的电子邮件通知问题 - 电子邮件过多
- javascript - 如何使用 React 中的 Material UI 以编程方式并排对齐 2 张卡片(在从 API 获取数据之后)?
- react-native - UseEffect 不被数据库更改调用
- azure-devtest-labs - Azure 开发测试实验室:管理工件存储库的 PAT
- google-bigquery - Bigquery 分区表中的重复项
- spring-boot - 即使 Elasticsearch 服务器正在运行,使用 ReactiveElasticsearchClient 的 Spring 应用程序也会无限期卡住
- ios - 如何在气隙 Mac 上安装新的 Apple 全球开发者关系中级证书?
- kubernetes - 在 Kubernetes 集群中共享静态数据