当前位置: 首页 > news >正文

自己做公司的网站优秀的网页设计案例

自己做公司的网站,优秀的网页设计案例,张家口互联网软件园,注册网站商标这是本人学习的总结,主要学习资料如下 - 马士兵教育 [TOC](目录)1、Eureka 1.1、架构 Eureka是SpringCloud Nexflix的核心子模块,其中包含Server和Client。 Server提供服务注册,存储所有可用服务节点。 Client用于简化和Server的通讯复杂…

这是本人学习的总结,主要学习资料如下
- 马士兵教育

@[TOC](目录)

1、Eureka

1.1、架构

EurekaSpringCloud Nexflix的核心子模块,其中包含ServerClient

Server提供服务注册,存储所有可用服务节点。

Client用于简化和Server的通讯复杂度。

下面是Eureka的简单架构图

在这里插入图片描述

每一个服务节点需要在Eureka Server中注册,如果需要其他节点的服务,则需要远程调用Service ProviderProvider会访问Server,由Server找到一个合适的节点提供服务给cumsumer



1.2、核心特性

  1. 服务注册:这是最核心的功能,其余的特性都是对这个功能的加强。
  2. 服务续约:Client每隔30s就会向Server发送一次心跳来续约,超过90s没有续约就会被Server删除这个服务节点。
  3. 服务下线:Client可以主动向Server发送cancel命令优雅下线。
  4. 缓存注册列表:Client会缓存从Server获取的注册列表,并且每30s更新一次。

2、建立Spring Cloud项目

2.1、项目结构和父项目依赖

接下来就是代码展示如何配置启动serverclient,以及client之间获取信息。

这是项目结构,两个子module,分别是serverorder-clientuser-clientserver提供注册服务,另外两个作为client则是到server注册然后互相调用对方的服务。

在这里插入图片描述

这是根目录的dependency

<properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><java.version>1.8</java.version><spring.cloud.version>Hoxton.SR12</spring.cloud.version><spring.boot.version>2.3.12.RELEASE</spring.boot.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId><version>${spring.boot.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>${spring.boot.version}</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.30</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId><version>${spring.boot.version}</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-netflix-eureka-server</artifactId></dependency></dependencies>

2.2、启动Server

2.2.1、dependency

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

2.2.2、配置文件

resources/application.yml

spring:application:name: msb-eureka-server
server:port: 8761eureka:instance:#注册实例名称hostname: localhost#是否将自己的ip注册到eureka中,默认false 注册 主机名prefer-ip-address: true# Eureka客户端需要多长时间发送心跳给Eureka,表明他仍然或者,默认是30# 通过下面方式我们可以设置,默认单位是秒lease-renewal-interval-in-seconds: 10# Eurkea服务器在接受到实例最后一次发送的心跳后,需要等待多久可以将次实例删除# 默认值是90# 通过下面方式我们可以设置,默认单位是秒lease-expiration-duration-in-seconds: 30client:#是否注册到eureka服务中register-with-eureka: false#是否拉取其他服务fetch-registry: false

2.2.3、Server端启动代码

@EnableEurekaServer
// 因为一直报Gson包冲突所以加上了exclude
@SpringBootApplication(exclude = {GsonAutoConfiguration.class})
public class EureakServerApplication {public static void main(String[] args) {SpringApplication.run(EureakServerApplication.class);}
}

启动以后打开网页检查。localhost:8761
请添加图片描述


2.3、启动Client

2.3.1、dependency

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

2.3.2、配置文件

order-client和```user-client````都一样,因为是单机模拟所以监听的端口号不同。

# 节点在server中注册的名字
spring:application:# user-client则用user-clientname: order-client
server:
# order-client 监听9002, user-client监听9003port: 9002eureka:client:# 这个一定要配对,server地址后面默认要加一个上下文eurekaservice-url:defaultZone: http://localhost:8761/eurekamanagement:endpoints:web:exposure:include: shutdown #暴露shutdown端点endpoint:shutdown:enabled: true #再次确认暴露shutdown端点feign:tokenId: 11111111111111111111

2.3.3、Client端启动代码

注意有两个注解可以将其标注为Client,分别是@EnableDiscoveryClient@EnableEurekaClient

这里推荐使用@EnableDiscoveryClient,因为后者是netfliex提供的,如果使用后者,后期要更换其它注册中心就需要更换注解,比较麻烦。

这是order-client的代码

@EnableDiscoveryClient // 这是官方提供的  ,我们以后可能切换其他的注册中心比如说nacos,那我们就直接切换就行了
//@EnableEurekaClient  // 是netflix提供的,如果用这个注解就只能服务于eureka
@SpringBootApplication
public class EurekaOrderClientApplication {public static void main(String[] args) {SpringApplication.run(EurekaOrderClientApplication.class);}
}

这时user-client的代码

@EnableDiscoveryClient // 这是官方提供的  ,我们以后可能切换其他的注册中心比如说nacos,那我们就直接切换就行了
//@EnableEurekaClient  // 是netflix提供的,如果用这个注解就只能服务于eureka
@SpringBootApplication(exclude = {GsonAutoConfiguration.class})
public class EurekaUserClientApplication {public static void main(String[] args) {SpringApplication.run(EurekaUserClientApplication.class);}
}

到Server的页面查看,两个Client都注册成功。
在这里插入图片描述

2.3.4、提供RPC服务

因为RPC是基于HTTP实现的协议,所以我们提供RPC服务时就像写一个controller的服务一样。

这里设定order模块会调用user提供的服务。

@Slf4j
@RestController
public class UserController {@RequestMapping("/getUserInfo")public String getUser(String userId) {log.info(userId);	return "userInfo: {userId: "+ userId +"}";;}
}

接下来就看order模块如何通过Eureka调用user提供的服务。

2.4、服务之间获取信息

引入LoadBalancerClient,从这个bean中可以获得其他注册的client元数据,比如地址,端口号等。

获取到这些信息后就可以组成请求地址,然后获取数据。

下面这个例子展示了如何获取其他client的元信息并且调用其它client的服务。

@Service
public class OrderService {@Autowiredprivate LoadBalancerClient eurekaClient;@Autowiredprivate RestTemplate restTemplate;public void getUser() {ServiceInstance instance = eurekaClient.choose("msb-user");String hostname = instance.getHost();int port = instance.getPort();String uri = "/getUserInfo?userId=" + userId;String url = "http://" + hostname + ":" + port + uri;return restTemplate.getForObject(url, String.class);}}
http://www.hrbkazy.com/news/29119.html

相关文章:

  • 企业vi系统设计公司在运营中seo是什么意思
  • 重庆公司网站百度应用下载安装
  • 网站推广的方法和途径广州最新疫情最新消息
  • macbook做网站绑定域名品牌推广网络公司
  • 专线网站建设网络营销推广方案模板
  • 高端网站建设jm3q淮北网站建设
  • 佛山市禅城网站建设公司襄阳seo
  • 基于html css的网站设计深圳网站建设开发公司
  • java电商网站开发视频教程昆明装饰企业网络推广
  • 网站建设包含哪些建设阶段北京seo网站开发
  • 大连做网站孙晓龙西安企业seo外包服务公司
  • 怎么做浏览器网站网络营销主要内容
  • 网站全屏弹出窗口开封网站快速排名优化
  • 网站开发 英文产品如何做市场推广
  • 金融企业网站建设网站提交收录入口
  • 做网站注册会员加入实名认证功能新浪微博指数查询
  • 网站建设要咨询哪些找资源的关键词有哪些
  • 工作号做文案素材的网站网页搜索
  • 免费学校网站建设软文范例大全500字
  • 教做发绳的网站公司做网站需要多少钱
  • 站群注册域名费用一般多少钱
  • 人力资源网站模板成人速成班有哪些专业
  • 网站开发技术部分短视频推广渠道有哪些
  • 网站建设延期合同书免费创建自己的网站
  • 延庆县专业网站制作网站建设网店搜索引擎优化的方法
  • 公司年前做网站好处品牌的宣传及推广
  • 网站建设前期准备工作总结如何做电商赚钱
  • 广州励网网站建设网络公司搭建自己的网站
  • 网站建设执招标评分表河源今日头条新闻最新
  • 有专业制作网站的公司吗百度seo整站优化