请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

github上Webhook配置的/monitor问题不起作用

配置方式都是跟老师的一模一样,

http://43in8i.natappfree.cc/actuator/bus-refresh

用这个链接刷新是OK的但是在Github上配置

http://43in8i.natappfree.cc/monitor

就不行

https://img1.sycdn.imooc.com//szimg/5b1582fb00019d6415200804.jpg

https://img1.sycdn.imooc.com//szimg/5b1582fb0001fa1f15800698.jpg

上面两张图是github的webhooks 的请求记录。



正在回答

8回答

同学你好,我们现在做问题回访,请你的问题最后得到了解决吗?

0 回复 有任何疑惑可以回复我~
  • 提问者 慕仙4974986 #1
    问题没有解决
    回复 有任何疑惑可以回复我~ 2018-07-04 12:30:26
  • wirechen 回复 提问者 慕仙4974986 #2
    你开个稳定的穿透隧道,把项目启起来我帮你看看
    回复 有任何疑惑可以回复我~ 2018-07-04 12:41:25
  • 提问者 慕仙4974986 #3
    我特的去开的,就是稳定的隧道,怎么联系你
    回复 有任何疑惑可以回复我~ 2018-07-06 15:03:59
十年一觉梦方醒 2018-07-08 06:38:15

9. Push Notifications and Spring Cloud Bus

Many source code repository providers (such as Github, Gitlab, Gitee, or Bitbucket) notify you of changes in a repository through a webhook. You can configure the webhook through the provider’s user interface as a URL and a set of events in which you are interested. For instance, Github uses a POST to the webhook with a JSON body containing a list of commits and a header (X-Github-Event) set to push. If you add a dependency on the spring-cloud-config-monitor library and activate the Spring Cloud Bus in your Config Server, then a /monitor endpoint is enabled.

When the webhook is activated, the Config Server sends a RefreshRemoteApplicationEvent targeted at the applications it thinks might have changed. The change detection can be strategized. However, by default, it looks for changes in files that match the application name (for example, foo.properties is targeted at the fooapplication, while application.properties is targeted at all applications). The strategy to use when you want to override the behavior is PropertyPathNotificationExtractor, which accepts the request headers and body as parameters and returns a list of file paths that changed.

The default configuration works out of the box with Github, Gitlab, Gitee, or Bitbucket. In addition to the JSON notifications from Github, Gitlab, Gitee, or Bitbucket, you can trigger a change notification by POSTing to /monitor with form-encoded body parameters in the pattern of path={name}. Doing so broadcasts to applications matching the {name} pattern (which can contain wildcards).


上面是官方文档的说明,请注意带下划线的部分。言下之意就是会根据配置文件的名字来匹配应用的名字。如果git上有order.yml, order-dev.yml 两个配置文件,那么修改order-dev.yml文件时不能刷新config-client的配置,因为无法找到order-dev这么一个注册的服务。 但修改order.yml时,则会刷新config-client(即注册的order服务)。 

结论就是要想让webhook里配置的/monitor方式对config-client起作用,修改{ApplicationName}.yml文件即可。 修改{ApplicationName}-{profile}这样的配置文件,是不行的。

4 回复 有任何疑惑可以回复我~
  • 确实如此,但是视频里就是修改order-test.yml实现动态更新的,好奇怪
    回复 有任何疑惑可以回复我~ 2018-08-02 20:09:53
  • 我也遇到这个问题,试了下确实是这样的,为什么呢?
    回复 有任何疑惑可以回复我~ 2018-11-27 19:08:12
  • 并且老师的视频中也没有引入spring-cloud-config-monitor,这是为什么呢
    回复 有任何疑惑可以回复我~ 2018-11-27 19:18:52
hellozjf 2018-08-03 07:48:04

开启spring-cloud-config-monitor之后也不行,因为这是spring cloud bus的一个bug,详见https://github.com/spring-cloud/spring-cloud-bus/issues/124

0 回复 有任何疑惑可以回复我~
十年一觉梦方醒 2018-07-08 03:56:10

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-config-monitor</artifactId>
</dependency>

在config-server的配置文件中加上这个依赖就可以开放/monitor接口的访问了

0 回复 有任何疑惑可以回复我~
  • 在config-server中加入这个依赖,只是修改order.yml配置时能实时刷新配置,但修改order-test.yml就不刷新了,这个是为什么呢?
    回复 有任何疑惑可以回复我~ 2018-11-27 19:23:09
  • bgkp #2
    正解!
    回复 有任何疑惑可以回复我~ 2019-05-18 13:04:40
张小泰 2018-07-02 10:33:15

我也正有此疑问,为什么在给oschina 使用 actuator/bus-refresh 做演示 ,到github就是变成/monitor,我用postman 试过本地去吊用 monitor 也是404

0 回复 有任何疑惑可以回复我~
黑鹰2 2018-06-29 17:47:47

补充:

application.yml如下:

spring:
  application:
    name: config
  cloud:
    bus:
      trace:
        enabled: true

    config:
      server:
        git:
          uri: https://github.com/xyang0917/springcloud-config
          username: xyang0917@gmail.com
          password: xxxxx
          basedir: /Users/yangxin/Documents/project/Java/springcloud/config/repository

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8762/eureka/
management:
  endpoints:
    web:
      exposure:
        include: "*"


0 回复 有任何疑惑可以回复我~
黑鹰2 2018-06-29 17:42:55

我也遇到了同样的问题,/monitor接口不能访问。Config Server好像没有开启/monitor接口

下面是Config Server的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <groupId>com.yangxin</groupId>
    <artifactId>config</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>config</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <!--<version>2.0.0.M3</version>-->
        <version>2.0.0.BUILD-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>


0 回复 有任何疑惑可以回复我~
wirechen 2018-06-05 12:54:21

你在gitee上试过吗?然后你本地能访问,github却报404会不会你那个穿透的隧道国外网络访问不了?

0 回复 有任何疑惑可以回复我~
  • 提问者 慕仙4974986 #1
    http://buxesa.natappfree.cc/actuator/bus-refresh
    这是在gitee上测试,还是不行
    {"timestamp":"2018-06-05T06:12:41.880+0000","status":400,"error":"Bad Request","message":"JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_ARRAY token\n at [Source: (PushbackInputStream); line: 1, column: 314] (through reference chain: java.util.LinkedHashMap[\"commits\"])","path":"/actuator/bus-refresh"}
    回复 有任何疑惑可以回复我~ 2018-06-05 14:13:59
  • 提问者 慕仙4974986 #2
    http://buxesa.natappfree.cc/monitor
    
    如果是这个url同样不行
    
    {"timestamp":"2018-06-05T06:14:47.541+0000","status":404,"error":"Not Found","message":"No message available","path":"/monitor"}
    回复 有任何疑惑可以回复我~ 2018-06-05 14:15:50
  • 提问者 慕仙4974986 #3
    问题没有解决
    回复 有任何疑惑可以回复我~ 2018-07-04 12:29:57
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信