上篇很虚的讲了一下我认为的微服务。既然微服务那么好,我现在如果想很快的搭建一个微服务系统,而且满足内聚、独立部署、分布式的特点,有没有很快的方式?
有的。由于身为菜鸟的我只对Java熟悉,这里推荐一下Java的spring-boot框架,其他语言肯定也有大神已经给出了可以快速搭建系统的方案,自己动手丰衣足食啊。
闲话不多说,直接上代码地址:https://github.com/chxfantasy/micro-service-sample
依赖
java 8
maven 3
但是因为我的程序里面配置了mongodb、redis、etcd等,要run起来我这个程序,这些依赖也不可少。后面会介绍在我的程序里去掉这些多余配置应该怎么做
运行命令
mvn spring-boot:run
集群部署
首先是编译和打包:mvn clean package -DskipTests(是否不运行单元测试)
打包之后,在target/目录会生成 micro-service-sample-0.0.1-SNAPSHOT.jar, 将这个文件copy到服务器,直接java -jar micro-service-sample-0.0.1-SNAPSHOT.jar 就可以完成部署。当然,建议在java -jar命令中指定java的运行参数,堆大小栈大小等
代码包含的功能
mybatis and a plug-in for paging, named pageHelper
multi database configuartions, primary db, slave db and read-only db
a custom annotation used for dynamicaly chosing db from multi dbs
using druid from alibaba as the datasource
basically some demo filters and intercepters, definited by annotations
a RequestLocaleResolver for internationality
logging based on slf4j and logback, with customising the log format
redis connection config and sample in unit test
mongodb connection config and sample in unit test, with mongodb 10. deployed on Replica Set way
etcd, zookeeper
this sample does not contains the jms and mq module, for i think the guildline of spring-boot is detailed enough, http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-messaging
作者:不如假如
链接:https://www.jianshu.com/p/e55b1c7b5dc5