近两三年的时间,微服务是热度陡增,做为旧有SOA体系的一下特殊展示,在企业级应用市场上面应用愈来愈普遍,愈来愈多的团队,开始采用微服务架构来改造现有的架构体系。无论实施的状况如何,至少已经有成形的案例在线上跑。哪咱们这些远未达到微服务架构的产品该如何呢,手痒的话就本身动手鼓捣吧,毕经并非都有那样的环境来运用微服务技术。
java
微服务架构部署运维起来很庞大繁杂,但最终提供服务的仍是那些被拆分的很细小的子服务,这些子服务最终是以什么形式编写构造出来的?这并非什么神秘的东西,你们都知道微服务体系是语言无关的,它能够融合各类语言的服务进来,因此不一样的语言提供的那些开箱即用的基本框架也是不同的。nginx
本篇主要仍是基于JAVA体系来讲一说那些让你分分钟构建一个WEB服务的基础框架吧。web
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.spring
从官方给出的定义就不难看出spring boot的雄心壮志,spring cloud全家桶微服务体系就是基于Spring Boot之上构建起来的,能够其战略地位之高。内置应用服务器无须部署war,听从约定优于配置的原则,简单maven配置,自动化配置spring。引入简单的jar后,便可轻松开启一个web服务。sql
<parent>
shell
<groupId>org.springframework.boot</groupId>
数据库
<artifactId>spring-boot-starter-parent</artifactId>
缓存
<version>1.5.7.RELEASE</version>
服务器
</parent>
架构
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
再看Java启动主类如何编写
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
测试时直接以main的方式运行起来。部署时直接以java -jar xxx.jar的方式运行咱们的子服务。
官网地址:http://www.dropwizard.io/1.1.4/docs/
Dropwizard is a Java framework for developing ops-friendly, high-performance, RESTful web services.
Dropwizard pulls together stable, mature libraries from the Java ecosystem into a simple, light-weight package that lets you focus on getting things done.
Dropwizard has out-of-the-box support for sophisticated configuration, application metrics, logging, operational tools, and much more, allowing you and your team to ship a production-quality web service in the shortest time possible.
Dropwizard与spring boot最大的不一样一在于,它帮助你离开对Spring的依赖,当下s、Spring几乎是Java世界的规范,这对于不使用Spring的团队来讲算是一个福音,但有多少这样的团队不使用Spring呢? Dropwizard还包含了不少其它很是有帮助的开发库,如Guava,Jackson,Logback,,sl4j,habernate,Httpclient,Jersey,Freemaker,Joda等等来帮助咱们快速构建服务。 从其官网提供的入门教程来看,相比Spring Boot来说仍是稍显复杂,但相较于传统的框架整合而言仍是至关简捷的。
简单作个历史回顾:
知道Wildfly的朋友估计很少,但提起JBoss的话熟识度应该是很高的。06年,JBoss被Redhat公司收购,收购后不久Redhat宣布,将JBoss Application Server(JBoss AS)正式改名为WildFly。 新名称WildFly反映了服务器“很是灵活、轻量、不羁、自由”的特性。
Wildfly-swarm是一个基于Wildfly-core的微服务项目,和Wildfly应用服务器共同使用相同的内核组件MSC,拥有类似的架构和开发/构建方法。
基础组件对好比下:
注入服务: Weld CDI容器
Web容器: 嵌入式的Undertow(Undertow 是红帽公司(RedHat)的开源产品,是 WildFly8(JBoos) 默认的 Web 服务器。)
Restful: RestEasy
持久层:采用JPA、Hibernate做为实现
嵌入式的数据库:HsqlDB和H2数据库
基于Maven、Gradle构建的方式
Play Framework makes it easy to build web applications with Java & Scala.Play is based on a lightweight, stateless, web-friendly architecture.
Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.
Play是一个开源的现代web框架,用于编写Java和Scala的可扩展Web应用程序。它经过自动重载变化来提升生产力,因为设计的就是一个无状态、无阻塞的架构,因此用Play框架来编写横向扩展Web应用程序是很容易的。
对于不在Java体系下开发微服务的话,相信其它语言也有对应的开箱便可的脚手架,来帮助你开发细粒度的服务体系,再结合相应的中间件如服务注册、发现,监控,服务熔断、降级等等,快速的上手一个微服务的案例。