make bus delay and timeout configurable

This commit is contained in:
Spencer Gibb
2015-05-22 14:06:11 -06:00
parent d67eb11032
commit 49467e4d4d
4 changed files with 43 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.bus.BusAutoConfiguration;
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
import org.springframework.context.annotation.Bean;
@@ -43,6 +44,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@ConditionalOnProperty(value = "spring.cloud.consul.bus.enabled", matchIfMissing = true)
@AutoConfigureAfter(BusAutoConfiguration.class)
@EnableScheduling
@EnableConfigurationProperties
public class ConsulBusAutoConfiguration {
@Autowired
@Qualifier("cloudBusInboundChannel")
@@ -51,6 +53,11 @@ public class ConsulBusAutoConfiguration {
@Autowired
ObjectMapper objectMapper;
@Bean
public ConsulBusProperties consulBusProperties() {
return new ConsulBusProperties();
}
@Bean
public EventService eventService() {
return new EventService();

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.consul.bus;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author Spencer Gibb
*/
@ConfigurationProperties("spring.cloud.consul.bus")
@Data
public class ConsulBusProperties {
boolean enabled = true;
int eventDelay = 10;
int eventTimeout = 2;
}

View File

@@ -59,7 +59,7 @@ public class ConsulInboundChannelAdapter extends MessageProducerSupport {
protected void doStart() {
}
@Scheduled(fixedDelayString = "10")
@Scheduled(fixedDelayString = "${spring.cloud.consul.bus.eventDelay:10}")
public void getEvents() throws IOException {
List<Event> events = eventService.watch();
for (Event event : events) {

View File

@@ -36,6 +36,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
*/
public class EventService {
@Autowired
protected ConsulBusProperties properties;
@Autowired
protected ConsulClient consul;
@@ -108,7 +111,7 @@ public class EventService {
if (lastIndex != null) {
index = lastIndex.longValue();
}
Response<List<Event>> watch = consul.eventList(new QueryParams(2, index));
Response<List<Event>> watch = consul.eventList(new QueryParams(properties.eventTimeout, index));
return filterEvents(readEvents(watch), lastIndex);
}