I have two questions:
- Does Spring cloud config can work with AWS code commit push notifications? AWS Codecommit can work with SNS that can send web hook
- Can the spring cloud config client run a task every x seconds that will call /acuator/refresh instead of using the spring cloud bus solution?
thanks, Avner Sternheim
Comment From: ryanjbaxter
Does Spring cloud config can work with AWS code commit push notifications? AWS Codecommit can work with SNS that can send web hook
From the docs...
The default configuration works out of the box with Github, Gitlab, Gitea, Gitee, Gogs 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={application}. Doing so broadcasts to applications matching the {application} pattern (which can contain wildcards).
Out o the box no, but you might be able to use the /monitor
endpoint.
Can the spring cloud config client run a task every x seconds that will call /acuator/refresh instead of using the spring cloud bus solution?
No not out of the box.
Comment From: avnerstr
I tried what you suggested and it seems to be working. The one thing that doesn't seem to be working is the profile
I have a client spring boot app that is running in profile: stage
when I run a curl:
curl -v -X POST "http://localhost:8888/monitor" \ -H "Content-Type: application/json" \ -H "Authorization: Basic dXNlcjE6dXNlcjE=" \ -d '{"path":["springboot-no-ui-tests"]}
the application request for new configuration. When I runt the curl:
curl -v -X POST "http://localhost:8888/monitor" \ -H "Content-Type: application/json" \ -H "Authorization: Basic dXNlcjE6dXNlcjE=" \ -d '{"path":["springboot-no-ui-tests-stage"]}'
it doesn't seem to ask.
I see those lines in the server side log:
2021-07-22 15:03:23.331 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Refresh not performed, the event was targeting springboot:no-ui-tests-stage: 2021-07-22 15:03:23.331 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: springboot-no:ui-tests-stage 2021-07-22 15:03:23.331 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. 2021-07-22 15:03:23.331 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Refresh not performed, the event was targeting springboot-no:ui-tests-stage: 2021-07-22 15:03:23.331 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: springboot-no-ui:tests-stage 2021-07-22 15:03:23.332 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. 2021-07-22 15:03:23.332 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Refresh not performed, the event was targeting springboot-no-ui:tests-stage: 2021-07-22 15:03:23.332 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: springboot-no-ui-tests:stage 2021-07-22 15:03:23.333 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. 2021-07-22 15:03:23.333 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Refresh not performed, the event was targeting springboot-no-ui-tests:stage: 2021-07-22 15:03:23.333 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: springboot-no-ui-tests-stage 2021-07-22 15:03:23.334 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. 2021-07-22 15:03:23.334 INFO [cloud-config-server,dbc177dbdbf18526,dbc177dbdbf18526] [nio-8888-exec-2] o.s.cloud.bus.event.RefreshListener : Refresh not performed, the event was targeting springboot-no-ui-tests-stage:**
but the client doesn't ask for updates.
any idea?
Comment From: avnerstr
it seems that when I changed the bus.id in the client, it worked. id: ${spring.application.name}:${spring.profiles.active}
I think this should be the default and not the only the application. WDYT?
Comment From: ryanjbaxter
The two post requests look identical to me.
Since the event was targeting springboot-no-ui-tests-stage:**
I think it should work regardless of the enabled profile.
Is that correct @spencergibb?
Comment From: spencergibb
The second one has -stage
at the end of path. If you are putting profile in the path you need to add the profile to the bus.id I think.
Comment From: ryanjbaxter
Arg, I missed that despite looking at it for a few minutes 🤦♂️
Seems like this test would cover this scenario... https://github.com/spring-cloud/spring-cloud-bus/blob/ee1015c225a97e904aa60e6ad2e611535ce4b589/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/PathServiceMatcherWithConfigNamesTests.java#L103
Can you provide us with the sample client application?
Comment From: spring-cloud-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: avnerstr
@ryanjbaxter as I said - I found the solution when I added the profile to the bus-id of the client: id: ${spring.application.name}:${spring.profiles.active}
but I think this should be the default of the id and not only the application. maybe here is not the forum, but the spring-bus.
Comment From: ryanjbaxter
I just noticed something strange...
Refresh not performed, the event was targeting springboot:no-ui-tests-stage:**
There is a :
between springboot
and no
, that should be a dash.
Is springboot-no-ui-tests
the name of the application?
Comment From: avnerstr
right, springboot-no-ui-tests is the name of the application
I think it ties all the options since it doesn't know when the application name ends and the profile starts, so it tires all the options. WDYT?
Comment From: avnerstr
@ryanjbaxter regarding my second question: Can the spring cloud config client run a task every x seconds that will call /acuator/refresh instead of using the spring cloud bus solution?
Any idea how this can be done? I get some objections to use bus in my company for this solution and I want to do some automatic refresh.
Comment From: avnerstr
is this task can do the job?
public class RefreshConfigurationTask {
private ApplicationEventPublisher eventPublisher;
public RefreshConfigurationTask(ApplicationEventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@Scheduled(fixedRate = 10000)
public void RefreshConfiguration(){
eventPublisher.publishEvent(new RefreshEvent(this, "RefreshEvent", "Refreshing scope"));
}
}
another solution I tried is to call the client /actuator/health according to the doc, it sounds like it suppose to refresh the client configuration: "Health Indicator The Config Client supplies a Spring Boot Health Indicator that attempts to load configuration from the Config Server. The health indicator can be disabled by setting health.config.enabled=false. The response is also cached for performance reasons. The default cache time to live is 5 minutes. To change that value, set the health.config.time-to-live property (in milliseconds)."
but it doesn't seem to work. Does it suppose to refresh client configuration and refresh the beans? if not, what it is used for, in the client side. it's not clear
Comment From: ryanjbaxter
I think it ties all the options since it doesn't know when the application name ends and the profile starts, so it tires all the options. WDYT?
Right you should not use dashes in the application name because the dash is used to indicate a profile.
Can the spring cloud config client run a task every x seconds that will call /acuator/refresh instead of using the spring cloud bus solution?
No, not out of the box.
but it doesn't seem to work. Does it suppose to refresh client configuration and refresh the beans? if not, what it is used for, in the client side. it's not clear
No it does not, its just used to indicate if the client can reach the config server.
Comment From: avnerstr
regarding the task, I created the following:
@Slf4j public class RefreshConfigurationTask {
private ApplicationEventPublisher eventPublisher;
public RefreshConfigurationTask(ApplicationEventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@Scheduled(fixedRate = 10000)
public void refreshConfiguration(){
eventPublisher.publishEvent(new RefreshEvent(this, "RefreshEvent", "Refreshing scope"));
}
}
is there any risk in doing that? besides the affect on the refresh-scoped beans that I should be aware of?
Comment From: ryanjbaxter
I dont think so.
Another option is to do exactly what the refresh endpoint does https://github.com/spring-cloud/spring-cloud-commons/blob/main/spring-cloud-context/src/main/java/org/springframework/cloud/endpoint/RefreshEndpoint.java
But i dont think what you are doing will cause an issue
Comment From: avnerstr
thanks @ryanjbaxter I will try that.