星舟平台的使用(GIT、spring Boot 的使用以及swagger组件的使用)
一、介绍星舟平台
1、星舟简介
2、网关kong的介绍
3、客户端
1)、服务注册:Eureka
2)、客户端负载均衡:Ribbon
4、服务器端
1)、服务注册:Marathon+Marathon-LB、HAProxy+Confd+Etcd
2)、服务端负载均衡:HAProxy
5、pinpoint调用链技术
traceid 透明数据传输
6、服务调用可以使用ELK采集
7、服务隔离与降级hystrix
8、统一配置中心:Spring Cloud ConfigServer
9、服务契约 Swagger,可以产生一个线上的文档
10、星舟灰度发布
三种方式
1、不定向发布:按比例发布
2、定向挑选:和微服务路径相关
3、定向挑选:业务无关,和header有关
11、devops的实操过程
jenkins on mesos,相当于jenkins集群
每个jenkins都有其master和slave
12、基于深度学习框架Tensorflow的微服务弹性扩缩
13、下一步演进 service mesh(服务网格)
二、开启微服务之旅-SpringBoot入门
需要安装的软件
idea
jdk
git
postman
1、spring boot 的版本,只能选择1.5.X版本
2、使用idea做一个Hello World!
步骤:
1)、创建一个spring boot
GRoup 为com.unicom.microserv.px
artifact:px190327_学号,我的是px190327_38023
选择web 和actuator
finish
删除一些目录,.mvn相关的三个文件或者目录等
http://localhost:8080/health
有正常返回即可:{"status":"UP"}
2)、增加HelloWorld
增加一个包controller
增加一个类HelloController
增加类注解
@RestController
@RequestMapping(value="/px190327/38023")
在类中增加一个类
并增加注解,代码如下:
@RequestMapping(
value = "hello",
method = RequestMethod.GET
)
public String hello() {
return "Hello World!38023";
}
3)、访问http://localhost:8080/px190327/38023/hello
Hello World!
3、Spring Boot的5种传参方式
注解 传参方式
@PathVariable 路径参数
@RequestParam Query参数;
表单@RequestBody Body参数
@RequestHeader Header参数
@CookieValue Cookie参数
@PathVariable和@RequestParam的使用
并增加注解,代码如下:
@RequestMapping(
value = "hello/{name}",
method = RequestMethod.GET
)
public String hello(@PathVariable String name,
@RequestParam ("say") String say) {
return "Hello World!" + name +"speak"+say;
}
访问http://localhost:8080/px190327/38023/hello/38023?say="Here Are You!"
2019年3月27日下午
三、Git学习(版本控制)
GitLab地址:http://10.172.49.22:8825/
账户:注册
星舟管理平台:地址:http://10.172.49.22:8086/microservadmin/login
账户: 同GitLab
天宫DCOS:地址:http://10.172.49.2/#/dashboard
账户:skyark_XXX/skyark_XXX(注意不要使用其他账号)
网络环境需要打开
http://10.125.128.49:9999/service/jenkins/job/cbproject1_feature_1036_release20190112/1/console
Git的工作区、缓存区、版本库 Working Directory /staging Directory/history Directory
git命令:
git add
git commit; #提交版本
git status
git rm
git mv
gitignore 不做版本控制的文件列表
git init 创建仓库
git remote add origin {URL} 添加远程库
git push [–u origin master] 推送到远程库
git pull 拉取到本地
git checkout {branch-name} 切换分支
git status 查看文件状态
本地分支和github/gitlabrary 服务器上分支
idea的工程的本地版本管理
vcs->->import into version control->create Git repostory
这是文件变红,表示未更新,右下角 有关各 git master
工程目录 右键 -》git ->add
工程目录 右键 -》git ->commit directory ,需要填写 commit text 和 username 以及邮件 ,username 以及邮件见邮件,正常提交后文件颜色恢复正常
星舟配置http://10.172.49.22:8086/microservadmin/login
登录后
研发流程管理->CICD->Git项目管理,新建项目
组名px190327
Git工程名 和本地一样,我的是px190327_38023
拷贝出来git地址http://10.172.49.22:8825/px190327/px190327_38023.git
idea中
git-repository-remote弹出一个对话框,点击+ ,origin不动,在输入框后粘贴拷贝出来的git地址,提交后,弹出需要输入用户名+密码 ok
git-repository-push,push成功
在天舟中可以看到对应的项目中的分支为master ,证明上传成功。
注意:
如果刚开始在填写用户名和右键是输入和远程的用户名不一致时,会出现问题,需要删除重新增加,在控制面板->用户账户->凭据管理器->管理windows凭据 删除
切换分支
星舟管理平台,项目管理,找到自己的工程,点击右侧的添加分支 起名为feature_0327,在idea中git-repository-pull,选中服务器上的feature_0327分支,在idea的右下角git master 点击后选择新的分支。即可使用分支开发
checkout,即切换到新的分支
完成修改后,push后,在星舟平台会自动构建,完成后,在天宫平台登录的组件仓库中可以看到该组件,点击操作下的安装组件包,点击 预览及运行,点击运行,等几分钟后再服务中可以看到
在服务->px190327中可以看到对应的服务运行起来了,点击服务,再点击具体的服务名,并在详情中可以看到服务地址和端口http://10.125.128.22:15295
浏览器中打开
http://10.125.128.22:15295/px190327/38023/hello/38023?say="I LOVE YOU!" 本地没问题,这里还有问题
疑问:怎么看marathon转后的地址和前面的地址
服务实践:
URL 动作 功能
/users GET 获取所有用户列表
/users POST 增加一个用户
/users/{id} GET 根据ID获取用户
/users/{id} PUT 修改ID为1的用户
/users/{id} DELETE 删除ID删除用户
/users/name/{name} GET 根据name查找用户
/users/{id}/age GET 获取用户的年龄
怎么发布?
增加一个User类(包含age和name两个属性)
public class User {
Integer age;
String name;
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
新增加一个类UserController,增加方法 如下
@RequestMapping(
value = "users",
method = RequestMethod.GET
)
public String getAllUser() {
return "返回所有user信息!";
} //这里可以修改为返回user列表
@RequestMapping(
value = "user",
method = RequestMethod.POST
)
public String createUser() {
return "增加一个用户!";
}
http://localhost:8080/px190327/38023/users,为空即可
接口文档的编写:http://10.172.49.22:8825/peixun/peixun_demo1/wikis/home这里有说明,见Swagger的学习.docx
1、增加Swagger依赖到Maven
2. 入口类注解@EnableSwagger2
3. Swagger配置类SwaggerConfig.java
4. 注解到接口方法@ApiOperation
5. localhost:8080/swagger-ui.html
6. @ApiIgnore 入口类
@ApiOperation 方法说明 value 为标题 ,notes为说明,不限制长度
@ApiModel 类说明
@ApiModelProperty 类的属性说明
操作过程
1、增加Swagger依赖到Maven
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
2、在入口增加注解 @EnableSwagger2,代码变为
@SpringBootApplication
@EnableSwagger2
public class Px19032738023Application {
public static void main(String[] args) {
SpringApplication.run(Px19032738023Application.class, args);
}
}
3、新增加config包增加配置类SwaggerConfig.java
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.produces(Sets.newHashSet("application/json"))
.consumes(Sets.newHashSet("application/json"))
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors
.basePackage("com.unicom"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo()
{
return new ApiInfoBuilder()
.title("peixun_liuyf")
.version("1.0.0")
.build();
}
}
4、增加说明
getAllUser方法上增加说明
@ApiOperation(
value="使用get获取user列表",
notes="通过get方法获取所有用户的列表,这里是示例,仅适用STring,正式环境需要有列表来返回!"
)
User属性增加注解和说明
@ApiModelProperty(value="年龄",notes="user的年龄",example = "23") //这个是引入swagger类以后增加
Integer age;
@ApiModelProperty(value="姓名",notes="user的姓名",example = "张三") //这个是引入swagger类以后增加
String name;
5、增加类getUserById定义
@RequestMapping(
value = "getUserById",
method = RequestMethod.GET
)
@ApiOperation(
value="根据id使用get获取user列表",
notes="根据Id 通过get方法获取所有用户的列表!"
)
public User getUserById(@RequestParam ("userId") Integer userId) {
User user=new User();
user.setAge(1);
user.setName("luhq7");
return user;
}
访问测试:http://localhost:8080/px190327/38023/getUserById?userId=9,
6、测试Swagger效果
访问:http://localhost:8080/swagger-ui.html
属性相关的说明可以在对应的接口中的model中看到
在接口的说明中可以看到@ApiOperation的说明
星舟平台的使用(GIT、spring Boot 的使用以及swagger组件的使用)的更多相关文章
- Spring Boot项目简单上手+swagger配置+项目发布(可能是史上最详细的)
Spring Boot项目简单上手+swagger配置 1.项目实践 项目结构图 项目整体分为四部分:1.source code 2.sql-mapper 3.application.properti ...
- Spring boot 多模块项目 + Swagger 让你的API可视化
Spring boot 多模块项目 + Swagger 让你的API可视化 前言 手写 Api 文档的几个痛点: 文档需要更新的时候,需要再次发送一份给前端,也就是文档更新交流不及时. 接口返回结果不 ...
- 15、Spring Boot 2.x 集成 Swagger UI
1.15.Spring Boot 2.x 集成 Swagger UI 完整源码: Spring-Boot-Demos 1.15.1 pom文件添加swagger包 <swagger2.versi ...
- Spring boot 、mybatis、swagger、c3p0、redis 和mongodb 整合
文件路径: 添加依赖: <?xml version="1.0" encoding="UTF-8"?> <project ...
- Spring Boot 、mybatis 、swagger 和 c3p0 整合
文件路径如下 添加依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...
- Spring boot 、mybatis 和 swagger 整合
文件路径 添加依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...
- Spring Boot之注册servlet三大组件
由于Spring Boot默认是以jar包的形式启动嵌入式的Servlet容器来启动Spring Boot的web应用是,没有web.xml配置文件 注册三大组件用以下方式 ServletRegist ...
- 剑指架构师系列-持续集成之Maven+Nexus+Jenkins+git+Spring boot
1.Nexus与Maven 先说一下这个Maven是什么呢?大家都知道,Java社区发展的非常强大,封装各种功能的Jar包满天飞,那么如何才能方便的引入我们项目,为我所用呢?答案就是Maven,只需要 ...
- spring boot之使用springfox swagger展示restful的api doc
摘要 springfox swagger展示restful的api doc, swagger is A POWERFUL INTERFACE TO YOUR API. 新增文件: import org ...
随机推荐
- 集合家族——List集合汇总
一.概述 List继承了Collection,是有序的列表. 可重复数据 实现类有ArrayList.LinkedList.Vector.Stack等 ArrayList是基于数组实现的,是一个数组队 ...
- dosbox+masm汇编环境的安装和使用
1. 下载dosbox安装程序:DOSBox0.74-win32-installer.exe 链接:https://pan.baidu.com/s/1gXPKTT-xKb6BpjOJdhmudA 密码 ...
- Undertow
Spring Boot 内嵌容器Undertow参数设置 配置项: # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程 # 不要设置过大,如果过大,启动 ...
- elasticsearch 内部对象结构数据索引
内部对象 经常用于 嵌入一个实体或对象到其它对象中.例如,与其在 tweet 文档中包含 user_name 和 user_id 域,我们也可以这样写: { "tweet": &q ...
- tomcat 启动报错org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].xxx
今天在写完一个非常简单的servlet页面跳转的web项目后,启动tomcat报错org.apache.catalina.LifecycleException: Failed to start com ...
- 一、Linux的基础使用--登录、开关机与在线、命令的查询帮助
目录 一.Linux的基础使用 1.1 X Window 与命令行模式的切换 1.2 命令行模式下命令的执行 1.3 修改支持语系 1.4 基础命令的操作 1.5 几个重要的热键[Tab].[Ctrl ...
- 安装 PostgreSQL 时丢失 libintl-8.dll 解决方案
发表于 2013 年 11 月 13 日 修订于 2018 年 05 月 05 日 PostgreSQL 比 MySQL 有更多的高级特性,而且微信支付的数据库也是基于 PostgreSQL ...
- 阿里RDS数据库 全量备份恢复到本地MYSQL
阿里RDS数据库 全量备份恢复到本地MYSQL 1.首先下载RDS的全量备份 下载完成后上传到服务器备用 2.安装MySQL 5.6 首先删除机上其他的MySQL版本 检查系统是否安装其他版本 ...
- Spring事务管理5-----声明式事务管理(3)
声明式事务管理 基于注解 在配置文件中需要开启注解驱动<tx:annotation-driven transaction-manager="transactionManager&qu ...
- Linux信号、信号处理和信号处理函数
信号(signal)是一种软件中断,它提供了一种处理异步事件的方法,也是进程间惟一的异步通信方式.在Linux系统中,根据POSIX标准扩展以后的信号机制,不仅可以用来通知某种程序发生了什么事件,还可 ...