我是塞内卡的新朋友。我一直在尝试使两个微服务相互通信,但是我一直失败并得到以下错误:
错误:响应错误:404未找到 在module.exports.internals.Utils.internals.Utils.handle_response(c:\ Users \ Actiview \ Desktop \ microservices \ orderManager \ node_modules \ seneca-transport \ lib \ transport-utils.js:71:11) 在c:\ Users \ Actiview \ Desktop \ microservices \ orderManager \ node_modules \ seneca-transport \ lib \ http.js:154:25 读取时(c:\ Users \ Actiview \ Desktop \ microservices \ orderManager \ node_modules \ wreck \ lib \ index.js:590:24) 完成时(c:\ Users \ Actiview \ Desktop \ microservices \ orderManager \ node_modules \ wreck \ lib \ index.js:398:20) 包装时(c:\ Users \ Actiview \ Desktop \ microservices \ orderManager \ node_modules \ hoek \ lib \ index.js:879:20) 在module.exports.internals.Recorder.onReaderFinish(c:\ Users \ Actiview \ Desktop \ microservices \ orderManager \ node_modules \ wreck \ lib \ index.js:449:16) 在Object.onceWrapper(events.js:313:30) 在emitNone(events.js:111:20) 在module.exports.internals.Recorder.emit(events.js:208:7) 在结束时也许(_stream_writable.js:614:14)
=== SENECA致命错误===消息:::: seneca:操作失败:响应错误:404错误。代码:::: act_execute实例::: Seneca / pcbyi7v5c76v / 1534346071465/6536 / 3.7.0 /-详细信息::: { 消息:“响应错误:找不到404”, 模式:“, fn:{[Function:transport_client] id:'host:127.0.0.2,pg:,port:8080'}, 打回来: {[功能:绑定的action_reply] 塞内卡: 塞内卡{ “私人$”: {行动: {父母: {开头:1534346071559, 结束:1534346071561,还有更多...
这是我的代码:
orderIndex.ts
{
const orderPlugin = require('./orderManagerPlugin');
const express = require('express');
const SenecaWeb = require('seneca-web');
const seneca = require("seneca")();
let bodyParser = require('body-parser');
var Routes = [{
prefix: '/orders',
pin: 'area:order,action:*',
map: {
fetch: { GET: true },
create: { GET: false, POST: true },
delete: { GET: false, DELETE: true },
}
}]
var config = {
routes: Routes,
adapter: require('seneca-web-adapter-express'),
context: express().use(bodyParser.urlencoded({ 'extended': 'true' })).use(bodyParser.json()),
options: {parseBody: false}
}
seneca.use(SenecaWeb,config);
seneca.use( orderPlugin );
seneca.ready(function (err) {
const app = seneca.export('web/context')();
app.listen({ host: "127.0.0.4", port: 8081 });
});
}
orderPlugin.ts
{
var plugin = function orderPlugin(options) {
var seneca = this;
var senecaEmailer;
seneca.add({ area: "order", action: "fetch" }, function (args,
done) {
var orders = this.make("orders");
orders.list$({ id: args.id }, done);
});
seneca.add({ area: "order", action: "delete" }, function (args,
done) {
var orders = this.make("orders");
orders.remove$({ id: args.id }, function (err) {
done(err, null);
});
});
seneca.add({ area: "order", action: "create" }, function (args,
done) {
console.log('create order');
senecaEmailer.act( 'role:web', {area: 'email', action:'send'} , done);
});
this.add( { init: "orderPlugin" }, function (args, done) {
senecaEmailer = require("seneca")().client({ host: "127.0.0.2", port: 8080 });
done();
});
}
module.exports = plugin;
}
emailIndex.ts
{
const mailPlugin = require('./emailingPlugin');
const express = require('express');
const SenecaWeb = require('seneca-web');
const seneca = require("seneca")();
let bodyParser = require('body-parser');
var Routes = [{
prefix: '/emails',
pin: 'area:email, action:*',
map: {
send: { GET: true },
}
}]
var config = {
routes: Routes,
adapter: require('seneca-web-adapter-express'),
context: express().use(bodyParser.urlencoded({ 'extended': 'true' })).use(bodyParser.json()),
options: {parseBody: false}
}
seneca.use(SenecaWeb,config);
seneca.use( mailPlugin );
seneca.ready(function (err) {
const app = seneca.export('web/context')();
app.listen({ host: "127.0.0.2", port: 8080 } );
});
}
emailPlugin.ts
{
import {EmailService} from './emailService';
var plugin = function emailPlugin(options) {
var seneca = this;
let mailer :EmailService ;
seneca.add({area: "email", action: "send"}, function(args, done) {
mailer.sendMail('guzon56@gmail.com', done);
});
this.add( { init: "emailPlugin" }, function (args, done) {
console.log('before init');
mailer = require('./emailService')();
console.log('after init');
done();
});
};
module.exports = plugin;
}
请帮助我。 Tnx。
答案 0 :(得分:0)
塞内卡由理查德·罗杰(Richard Rodger)在this post中进行了解释。 “服务发现”一章讨论了网络中微服务的网格化。
对于我的应用程序,我使用seneca-mesh插件。该插件自述文件说:
要加入网络,所有服务所需要做的就是互相联系 网络中已有服务。然后网络共享信息 关于哪些服务响应哪种模式。不需要 在任何地方配置单个服务的位置。
阅读Richard的文章和插件文档可能是您项目的一个很好的起点。希望对您有帮助!