星舟平台的使用(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 ...
随机推荐
- 域渗透-企业应用SAML签名攻击
在项目中遇到SAML企业应用 想留个后门时候一脸懵 随便的整理记录 记录项目中SAML渗透的知识点. 0x01 前置知识 SAML单点登陆 SAML(Security Assertion ...
- adb的一些命令
adb pull <手机路径> <本机路径> 从手机中拉取信息到本地电脑上 adb push <本机路径> <手机路径> 从本地电脑推送信息到手机上
- CISCO实验记录十:switch基本配置
1.交换机IP配置 2.配置telnet 1.交换机IP配置 #interface vlan 1 #ip address 192.168.0.3 255.255.255.0 #no shutdown ...
- EntityFramework Core Code First 已有数据库
问题场景:我已经有一个数据库,想用 EF core Code First,怎么办? 首先,可以参考微软的API文档:通过现有数据库在 ASP.NET Core 上开始使用 EF Core, 这一步可以 ...
- 高并发实时弹幕系统 并发数一定是可以进行控制的 每个需要异步处理开启的 Goroutine(Go 协程)都必须预先创建好固定的个数,如果不提前进行控制,那么 Goroutine 就随时存在爆发的可能。
小结: 1.内存优化1.一个消息一定只有一块内存使用 Job 聚合消息,Comet 指针引用. 2.一个用户的内存尽量放到栈上内存创建在对应的用户 Goroutine(Go 程)中. 3.内存由自己控 ...
- Mac os 安装 alipay-sdk-python 3.3.92错误 line 278,其实是另一个依赖包pycrypto安装有问题。
日期2019.7.17解决的问题. 系统mac os 10.14.5 python 3.6 django 1.11 要安装alipay-sdk-python 3.3.92错误 line 278, in ...
- StateListDrawable
可供设置的属性如下: drawable:引用的Drawable位图,我们可以把他放到最前面,就表示组件的正常状态~ state_focused:是否获得焦点 state_window_focused: ...
- python3 super().__init__() 和 __init__() 的区别
1.单继承 super().__int__()和 Base.__init__(self)是一样的, super()避免了基类的显式调用. class Base(object): def __init_ ...
- 利用matlab自带函数快速提取二值图像的图像边缘 bwperim函数
clear all;close all;clc; I = imread('rice.png'); I = im2bw(I); J = bwperim(I); % 提取二值图像图像边缘 figure ...
- ssh自动添加hostkey到know_hosts
The authenticity of host ‘git.sws.com (10.42.1.88)’ can’t be established. ECDSA key fingerprint is 5 ...