springcloud21---Config-bus实现配置自动刷新

Pivotal毕威拓)有VMwareEMC成立的.

RabbitMQ是由ERlang(爱立信开发的,面向并发的编程语言),安装RabbitMQ先要安装ERlang

package com.itmuch.cloud;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
//配置自动刷新,config server不用改,config client要改。
@RefreshScope //加入配置自动刷新注解,当配置发生更改的时候这个bean会
//各个微服务启动了,config client已经加载配置了,即使config server挂了也可以。
public class ConfigClientController {

  @Value("${profile}")
  private String profile;

  @GetMapping("/profile")
  public String getProfile() {
    return this.profile;
  }
}
package com.itmuch.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ConfigServerApplication {
  public static void main(String[] args) {
    SpringApplication.run(ConfigServerApplication.class, args);
  }
}

application.yml

server:
  port: 8082

bootstrap.yml

spring:
  cloud:
    config:  #config server的地址
      uri: http://localhost:8080
      profile: dev
      label: master   # 当configserver的后端存储是Git时,默认就是master 
    bus:
      trace:
        enabled: true
  application:
    name: foobar
  #连接rabbitmq
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.itmuch.cloud</groupId>
        <artifactId>microservice-spring-cloud</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>microservice-config-client-refresh</artifactId>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 配置自动刷新的依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>
    </dependencies>
</project>

微服务之间的事务是分布式的事务(TCC,可靠事务的补偿机制,最大努力型事务)。Eureka,zk,consul,etcd都是做服务发现的话是一样的不同的产品而已。使用docker可以一次性启动所有的微服务,java -jar一次只能启动一个微服务。

调用链尽可能短,否则会出现超时。

www.itmuch.com

微服务之间可以通过http或者rpc方式调用。SOAP协议很重,微服务之间的可以跨平台或者跨语言的。

客户端侧负载均衡:客户端可以算出来命中哪个服务端,那么服务端就没必要做负载均衡了。

nanoservices:比微服务更小的纳米服务框架。

Sidecar : 组件。

猜你喜欢

转载自www.cnblogs.com/yaowen/p/9190145.html
今日推荐