<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          MicroMono微服務(wù)框架

          聯(lián)合創(chuàng)作 · 2023-09-28 05:56

          MicroMono 可以使用整體風(fēng)格編寫微服務(wù)。MicroMono 是一個(gè)使用 monolithic 風(fēng)格開發(fā)微服務(wù)的框架,允許你切換和混合 微服務(wù)/整體 風(fēng)格,不需要修改代碼。之前兩者是通過 VS 連接,現(xiàn)在使用 micromono 可以很好的同時(shí)處理兩者。

          MicroMono 包括 3 部分:

          • Web 框架 (http 路由,中間件,頁面渲染等等)

          • 遠(yuǎn)程方法調(diào)用 (RPC)

          • 前端代碼管理 (JavaScript 和 CSS 靜態(tài)資產(chǎn)文件)

          MicroMono 包含兩種類型的組件:

          代碼示例

          定義一個(gè)服務(wù)

          // Require micromono and get the Service base class
          var Service = require('micromono').Service;
          // Subclass Service class to define your service
          // (Backbone/Ampersand style inheritance)
          var SimpleHttpService = Service.extend({
            // `route` is the object where you define all your routing handlers
            route: {
              'get::/hello/:name': function(req, res) {
                // Basically, this handler function will be directly attached to
                // internal express instance created by micromono. So, any express
                // route handler could be ported to micromono without any modification.
                var name = req.params.name;
                res.send('Hello, ' + name);
              }
            }
          });
          The 'get::/hello/:name': function(req, res){...} part in above example equivalents to:
          var app = express();
          app.get('/hello/:name', function(req, res){
            var name = req.params.name;
            res.send('Hello, ' + name);
          });

          服務(wù)初始化

          var bodyParser = require('body-parser');
          var Service = require('micromono').Service;
          var MongoClient = require('mongodb').MongoClient;
          module.exports = Service.extend({
            // initialization function takes no arguments
            init: function() {
              // get the internal express instance
              var app = this.app;
              // use a middleware
              app.use(bodyParser.json());
              var self = this;
              // create a new promise instance
              var promise = new Promise(function(resolve, reject){
                // do the async operation (connect)
                MongoClient.connect('127.0.0.1', function(err, db){
                  if (err) {
                    // reject the promise if there's an error
                    reject(err);
                    return;
                  }
                  self.db = db;
                  // resolve when done
                  resolve();
                });
              });
              // init function should return a promise no matter what
              return promise;
            }
          });
          
          瀏覽 34
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  69成人电影 | 内射网站大全中文 | 伊人网站在线免费观看 | 奇米色综合 | 综合无码 豆花视频 |