INT-4381: MessageSources refactoring (#2517)
* INT-4381: MessageSources refactoring JIRA: https://jira.spring.io/browse/INT-4381 * Make all the out-of-the-box `MessageSource` implementations based on the `AbstractMessageSource` * Fix `JdbcPollingChannelAdapterIntegrationTests` for sporadic failure because of `fixed-rate` for the poller * Fix HeaderEnricherTests race condition The `errorChannel()` expect an error in the `testErrorChannel` after `1000` ms, but at the same time the `poller` in configured for the `3000` ms. * Increase all the timeouts for replies * Decrease a `fixed-delay` on the `poller` * Some other code style polishing for the `HeaderEnricherTests`
This commit is contained in:
committed by
Gary Russell
parent
d6c8baf50f
commit
0d0605be78
@@ -28,11 +28,10 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.context.IntegrationObjectSupport;
|
||||
import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.endpoint.AbstractMessageSource;
|
||||
import org.springframework.integration.metadata.MetadataStore;
|
||||
import org.springframework.integration.metadata.SimpleMetadataStore;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -55,7 +54,7 @@ import com.rometools.rome.io.XmlReader;
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class FeedEntryMessageSource extends IntegrationObjectSupport implements MessageSource<SyndEntry> {
|
||||
public class FeedEntryMessageSource extends AbstractMessageSource<SyndEntry> {
|
||||
|
||||
private final URL feedUrl;
|
||||
|
||||
@@ -145,18 +144,7 @@ public class FeedEntryMessageSource extends IntegrationObjectSupport implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<SyndEntry> receive() {
|
||||
Assert.isTrue(this.initialized,
|
||||
"'FeedEntryReaderMessageSource' must be initialized before it can produce Messages.");
|
||||
SyndEntry entry = doReceive();
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
return this.getMessageBuilderFactory().withPayload(entry).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() throws Exception {
|
||||
protected void onInit() {
|
||||
if (this.metadataStore == null) {
|
||||
// first try to look for a 'messageStore' in the context
|
||||
BeanFactory beanFactory = this.getBeanFactory();
|
||||
@@ -176,13 +164,16 @@ public class FeedEntryMessageSource extends IntegrationObjectSupport implements
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
private SyndEntry doReceive() {
|
||||
@Override
|
||||
protected SyndEntry doReceive() {
|
||||
Assert.isTrue(this.initialized,
|
||||
"'FeedEntryReaderMessageSource' must be initialized before it can produce Messages.");
|
||||
SyndEntry nextEntry = null;
|
||||
synchronized (this.monitor) {
|
||||
nextEntry = getNextEntry();
|
||||
if (nextEntry == null) {
|
||||
// read feed and try again
|
||||
this.populateEntryList();
|
||||
populateEntryList();
|
||||
nextEntry = getNextEntry();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -75,7 +75,7 @@ public class FeedEntryMessageSourceTests {
|
||||
public void testReceiveFeedWithEntriesSorted() throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource("org/springframework/integration/feed/sample.rss");
|
||||
FeedEntryMessageSource source = new FeedEntryMessageSource(resource, "foo");
|
||||
source.setComponentName("feedReader");
|
||||
source.setBeanName("feedReader");
|
||||
source.setBeanFactory(mock(BeanFactory.class));
|
||||
source.afterPropertiesSet();
|
||||
Message<SyndEntry> message1 = source.receive();
|
||||
|
||||
Reference in New Issue
Block a user