0

我是新来的塞内卡。我一直在尝试让两个微服务相互通信,但我一直失败并出现以下错误:

错误:响应错误:404 Not Found at 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) 在 finishMaybe (_stream_writable.js:614:14) 的 module.exports.internals.Recorder.emit (events.js:208:7) 的 emitNone (events.js:111:20)

=== SENECA 致命错误 === 消息:::: seneca:操作失败:响应错误:404 未找到。代码::::act_execute INSTANCE ::: Seneca/pcbyi7v5c76v/1534346071465/6536/3.7.0/- DETAILS ::: { message: 'Response Error: 404 Not Found', pattern: '', fn: { [Function: transport_client] id: 'host:127.0.0.2,pg:,port:8080' }, callback: { [Function: bound action_reply] seneca: Seneca { 'private$': { act: { parent: { start: 1534346071559, end : 1534346071561, 更多...

这是我的代码:

订单索引.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 });
    });
    }

订单插件.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;
}

电子邮件索引.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 } );
});
}

电子邮件插件.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;
}

请帮我。肿瘤坏死因子。

4

1 回答 1

0

Richard Rodger 在这篇文章中解释了 Seneca 。“服务发现”一章讨论了网络中的微服务网格化。

对于我的应用程序,我使用seneca-mesh插件。这个插件自述文件说:

要加入网络,服务所要做的就是联系已经在网络中的另一个服务。然后,网络共享有关哪些服务响应哪些模式的信息。无需在任何地方配置单个服务的位置。

阅读 Richard 的帖子和插件文档可能是您项目的一个很好的起点。希望能帮助到你!

于 2018-08-17T10:42:55.380 回答