微服务框架 MicroMono

码农软件 · 软件分类 · 微服务框架 · 2019-03-18 12:41:41

软件介绍

MicroMono 可以使用整体风格编写微服务。MicroMono 是一个使用 monolithic 风格开发微服务的框架,允许你切换和混合 微服务/整体 风格,不需要修改代码。之前两者是通过 VS 连接,现在使用 micromono 可以很好的同时处理两者。

MicroMono 包括 3 部分:

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

  • 远程方法调用 (RPC)

  • 前端代码管理 (JavaScript 和 CSS 静态资产文件)

MicroMono 包含两种类型的组件:


代码示例

定义一个服务

// 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);
});

服务初始化

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;
  }
});


本文地址:https://codercto.com/soft/d/1614.html

HTML5权威指南

HTML5权威指南

[美] Adam Freeman / 谢廷晟、牛化成、刘美英 / 人民邮电出版社 / 2014-1 / 129.00元

《HTML5 权威指南》是系统学习网页设计的权威参考图书。本书分为五部分:第一部分介绍学习本书的预备知识和HTML、CSS 和JavaScript 的最新进展;第二部分讨论HTML 元素,并详细说明了HTML5中新增和修改的元素;第三部分阐述CSS,涵盖了所有控制内容样式的CSS 选择器和属性,并辅以大量代码示例和图示;第四部分介绍DOM,剖析如何用JavaScript 操纵HTML 内容;第五部......一起来看看 《HTML5权威指南》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码