Some people hear their own inner voices with great clearness. And they live by what they hear.Such people become crazy,or they become legends ......
有些人能分明地听到本人内心深处的声音,并以此行事。这些人要么变成了疯子,要么成为传奇。——《秋日传奇》
根本概述
A modern, JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications. ——by[https://micronaut.io/]
作为一名程序员,在微服务[MicroService]乱入的世界,听着拥抱云原生[Cloud Native],马踏无服务[Serverless]的论断。或者都会经不住引诱,会自主在搜寻相干的关键词去探索一下这些陈腐以及生疏的字眼。然而实际上,在通过事实的陶冶之后,咱们所摆弄的还是最原始的状态。大多数在进入一家企业之后,情不自禁的发现,在Spring的生态影响下,当初大部分程序员都沉闷在这个框架里。如果跳出这个框架之后,咱们是否还能对当初的工作得心应手,恐怕是要打上一个大大的问号的?在一次偶尔的机会,晓得了Micronaut。于是,开启了对Micronaut的摸索之路......
Micronaut is a modern, JVM-based, full stack Java framework designed for building modular, easily testable JVM applications with support for Java, Kotlin, and Groovy.
基于JVM的古代全栈Java框架,旨在通过反对Java,Kotlin和Groovy语言来构建模块化,易于测试的微服务应用程序以及无服务应用程序。
Micronaut is developed by the creators of the Grails framework and takes inspiration from lessons learnt over the years building real-world applications from monoliths to microservices using Spring, Spring Boot and Grails.
Micronaut由Grails框架的创建者开发,并借鉴了多年应用Spring,Spring Boot和Grails构建从单块到微服务的理论应用程序的经验教训。
Micronaut aims to provide all the tools necessary to build JVM applications including:
Dependency Injection and Inversion of Control (IoC)
Aspect Oriented Programming (AOP)
Sensible Defaults and Auto-Configuration
Micronaut旨在提供构建JVM应用程序所需的所有工具,包含:
- 依赖注入和管制反转(IoC)
- 面向方面的编程(AOP)
- 正当的默认设置和主动配置
With Micronaut you can build Message-Driven Applications, Command Line Applications, HTTP Servers and more whilst for Microservices in particular Micronaut also provides:
Distributed Configuration
Service Discovery
HTTP Routing
Client-Side Load Balancing
应用Micronaut,您能够构建音讯驱动的应用程序,命令行应用程序,HTTP服务器等,而对于Microservices,Micronaut特地提供以下性能:
- 分布式配置
- 服务发现
- HTTP路由
- 客户端负载平衡
At the same time Micronaut aims to avoid the downsides of frameworks like Spring, Spring Boot and Grails by providing:
Fast startup time
Reduced memory footprint
Minimal use of reflection
Minimal use of proxies
No runtime bytecode generation
Easy Unit Testing
同时,Micronaut旨在通过提供以下内容来防止诸如Spring,Spring Boot和Grails之类的框架的弊病:
- 疾速启动工夫
- 低内存占用
- 最小粒度应用反射
- 最小粒度应用代理
- 无运行时字节码生成
- 简略的单元测试
Historically, frameworks such as Spring and Grails were not designed to run in scenarios such as serverless functions, Android apps, or low memory footprint microservices. In contrast, Micronaut is designed to be suitable for all of these scenarios.
This goal is achieved through the use of Java’s annotation processors, which are usable on any JVM language that supports them, as well as an HTTP Server and Client built on Netty. To provide a similar programming model to Spring and Grails, these annotation processors precompile the necessary metadata to perform DI, define AOP proxies and configure your application to run in a low-memory environment.
Many APIs in Micronaut are heavily inspired by Spring and Grails. This is by design, and helps bring developers up to speed quickly.
综上所述,Micronaut设计的初衷是面向无服务,低内存占用的微服务等场景而生的。通过应用Java的(可在反对它们的任何JVM语言中应用)以及基于Netty构建的HTTP Server和Client 来实现此指标。提供与Spring和Grails类似的编程模型,利用批注处理器会预编译必要的元数据,以执行DI,定义AOP代理并配置您的应用程序以在低内存环境中运行。
根底配置
1.Micronaut SDK装置
This project implements a project generator for Micronaut as is both a Command Line (CLI) application and an API that can be run as a HTTP server, deployed to a Servlet container or executed on a Serverless platform (Google Cloud Run, Google Cloud Function, AWS Lambda or Azure Function).
目前Micronaut最新的版本为2.3.4。Micronaut创立工程实提供了Micronaut Command Line (CLI) 命令行和 Micronaut API接口2种形式,利用可部署在Servlet container[Web 容器]和Serverless Platform [无服务框架]平台。
SDK装置形式有以下几种:
- Install with SDKman
- Install with Homebrew
- Install with MacPorts
- Install with Chocolatey
- Install through Binary on Windows
- Build & Install from Source
在Unix/Linux环境应用SDKman装置:
[1].sdk update更新
sdk update
[1].sdk install micronaut 装置SDK
sdk install micronaut
在Mac环境应用Homebrew和MacPorts装置:
[1].MacPorts装置:
sudo port install micronaut
[2].Homebrew装置:
brew install --cask micronaut-projects/tap/micronaut
MacPorts的理念是尽量减少对系统现有库的依赖,因而它须要下载许多根底库,而后编译装置到零碎中。这样做最大的问题在于下载工夫长,编译工夫长,最大的益处就是不会毁坏零碎原有软件包。
[⚠️注意事项]:
1.Mac OSX零碎上有许多优良的包管理软件可能将Linux上罕用的命令工具和依赖装置到零碎上,次要有Fink、Macports、Homebrew这3个支流包管理软件。
2.MacPorts依赖于BSD的软件包管理工具(port),它的工作形式是从仓库中下载软件包以及其依赖库,而后在本机中编译装置。尽量减少对系统现有库的依赖,因而它须要下载许多根底库,而后编译装置到零碎中。这样做最大的问题在于下载工夫长,编译工夫长,最大的益处就是不会毁坏零碎原有软件包。
3.Homebrew与MacPorts的工作形式相似,也是从仓库中下载软件包以及其依赖库,而后在本机中编译装置。Homebrew的理念是尽量应用零碎中存在的库,且软件包都装置到/usr/local目录里,最大的益处就是下载编译工夫短于MacPorts,安装简单,且无需root用户权限来装置。
3.Fink是一个心愿把越来越多Unix上软件带到Mac OSX零碎上的我的项目。它通过移植软件源码,而后打包成能在Mac OSX零碎上执行的二进制进行散发。Fink依赖于Debian的软件包管理工具(dpkg/dselect/apt-get),因而它将软件包打包成.deb格局。这样做最大的益处就是装置软件是预编译好的,因而无需本机编译。Fink最大的问题在于软件包的更新迭代比较慢,因而要想应用最新版软件包,则须要期待Fink社区更新。
在Windows环境下,应用Chocolatey和Binary二进制文件装置:
[1].Chocolatey装置:
choco install micronaut
[2].Binary二进制装置:设置环境变量[%MICRONAUT_HOME%]
%MICRONAUT_HOME%\bin
除此之外还能够下载源码进行装置:
[1].利用Git克隆源码:
git clone https://github.com/micronaut-projects/micronaut-starter.git
[2].利用gradlew构建:
./gradlew micronaut-cli:assembleDist
[3].配置环境装置:
mkdir ~/.micronautunzip starter-cli/build/dist/micronaut-cli-VERSION.zip -d ~/.micronaut
[4].配置环境变量:
export MICRONAUT_HOME=~/path/to/unzipped/cliexport PATH="$PATH:$MICRONAUT_HOME/bin"
[4].配置环境变量失效:
source ~/.bash_profile
[⚠️注意事项]:
[1].源码装置以上形式反对Linux和Unix以及Macos
[2].Windows环境依照对应的配置即可
2.Micronaut SDK应用
个别创立代码应用mn命令:
mn create-[COMMAND] --build=BUILD-TOOL
[1].主函数mn: Micronaut CLI 提供的主函数名
- create-app NAME
- create-cli-app NAME
- create-function-app NAME
- create-grpc-app NAME
- create-messaging-app NAME
[2].--build:构建工具反对:gradle, gradle_kotlin, maven.
例如:
mn create-app pandora-cloud-framework --build maven
版权申明:本文为博主原创文章,遵循相干版权协定,如若转载或者分享请附上原文出处链接和链接起源。