【开源】嵌入式微服务框架MAES-LMLPHP

Github: https://github.com/jtttl/maes

MAES = Microservice Architecture on Embedded System.
MAES gives your system the abilities of :

  1. Build your service fast in C/C++;
  2. Multi-service or multi-process communication; (PUB/SUB and REQ/RESP)
  3. Write and save logs;
  4. Load configuration file and use configurations;

System Overview

【开源】嵌入式微服务框架MAES-LMLPHP

How To Use

#include <iostream>
#include <memory>

// maes include
#include "MaesService.h"

// Create a derived class from maes::ServiceHandler
class MqttService : public maes::ServiceHandler {
public:
    MqttService() {}
    virtual ~MqttService() {}

public:

    // path of storing all the log files
    std::string getLogPath() override {
        return "/tmp";
    }

    // path of configuration file
    std::string getConfigFile() override {
        return "/home/config.json";
    }

    // set your service name
    std::string getServiceName() override {
        return "mqtt-service";
    }

    // set your service version
    std::string getVersion()
    {
      	return "1.2.3";
    }

    // startup sequence 1 inside maes
    void onInit() override {
	// logs
	maeslog.debug("%s\n", __FUNCTION__);
    }

    // startup sequence 2 inside maes
    int initHal() override {
	maeslog.debug("%s\n", __FUNCTION__);
      	// init your hardware
      	// beep_init();
        // uart_init();
        // nfc_init();
        return 0;
    }

    // startup sequence 3 inside maes
    int initFml() override {
	maeslog.debug("%s\n", __FUNCTION__);
        // init your functions
      	// db_init();
      	// algorithm_init();
      	// encrypt_init();
        return 0;
    }

    // startup sequence 4 inside maes
    int initAppl() override {
      	// get configurations
	const int val = framework().getConfig()["mqtt-service"]["val"].asInt();

      	// do something
      	// ...

      	// main loop
      	while(1) {
          // ...
        }

        return 0;
    }

    // on maes exit
    void onExit() override {
	maeslog.debug("%s\n", __FUNCTION__);
    }
};

int main(int argc, char const *argv[]) {
    // put your service into the maes
    maes::Framework f(std::make_shared<TpuService>());
    // let's go
    return f.run();
}

Install

# Clone this repository
$ git clone https://github.com/jtttl/maes

# Go into the repository
cd maes

# Create build directory for cmake
mkdir my_build

# Go into my_build
cd my_build

# Set zmq lib and inc directories
cmake .. -DZMQ_LIB="..." -DZMQ_INC="..."

# Make
make

Why microservice

  1. Breaking your monolithic application into services, which are then loosely connected via APIs. This allows for improved scalability, better fault isolation, and faster time to market;
  2. Easy for two-pizza development teams;
  3. For embedded system or embedded devices, the communication is easily between your services in your device or amoung your devices;
  4. Hope you will love MAES;

Contact me

  • Email : jtttl1221@gmail.com
  • WeChat : jtl1221
09-18 05:43