zoukankan      html  css  js  c++  java
  • springcloud整合bus

    bus的使用主要是配合springcloud config部分来一起使用,并没有单独使用

    首先建立服务端:

     <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>

    由于本次使用的是rabbitmq进行监听

    所以需要在依赖中引入amqp。这是rabbitmq采用的协议

    server:
      port: 8080
    spring:
      application:
        name: microservice-config-server
      cloud:
        config:
          server:
            git:
              uri: https://git.oschina.net/itmuch/spring-cloud-config-repo      # 配置Git仓库的地址
              username:                                                         # Git仓库的账号
              password:                                                         # Git仓库的密码
        bus:
          trace:
            enabled: true     # 开启cloud bus的跟踪
      rabbitmq:
        host: localhost
        port: 5672
        username: guest
    password: guest

    然后再次配置连接,连接rabbitmq的地址

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.config.server.EnableConfigServer;
    
    @SpringBootApplication
    @EnableConfigServer
    public class ConfigServerApplication {
      public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
      }
    }

    再配置服务端:

    <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        
        <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>

    application.yml

    server:
    port: 8081

    bootstrap.yml

    spring:
      application:
        name: microservice-foo    # 对应config server所获取的配置文件的{application}
      cloud:
        config:
          uri: http://localhost:8080/
          profile: dev            # profile对应config server所获取的配置文件中的{profile} 
          label: master           # 指定Git仓库的分支,对应config server所获取的配置文件的{label}
      rabbitmq:
        host: localhost
        port: 5672
        username: guest
    password: guest
  • 相关阅读:
    用TextKit实现表情混排
    IOS类似9.png
    iphone 弹出键盘,文本框自动向上移动。
    IOS截取部分图片
    IOS给图片增加水印(图片、文字)
    iOS界面设计切图小结
    table tr th td thead tbody tfoot
    怎样让table没有边框
    margin、padding,border默认值
    Java 随机数
  • 原文地址:https://www.cnblogs.com/xiufengchen/p/10450840.html
Copyright © 2011-2022 走看看