Reputation: 1685
I have a stream that includes a module that behaves similarly to the source:file module, with the exception that files will only be detected once using a redisMetaDataStore and Spring Integration's FileSystemPersistentAcceptOnceFileListFilter so that the module remembers what files were already read between container restarts.
file-persisting.xml
<beans:bean id="redisMetadataStore" class="org.springframework.integration.redis.metadata.RedisMetadataStore" >
<beans:constructor-arg ref="redisConnectionFactory" />
</beans:bean>
<beans:bean id="persistentAcceptOnceFileFilter" class="org.springframework.integration.file.filters.FileSystemPersistentAcceptOnceFileListFilter">
<beans:constructor-arg ref="redisMetadataStore" />
<beans:constructor-arg value="${metadataPrefix}" />
</beans:bean>
<beans:bean id="antPatternFileFilter" class="org.springframework.integration.file.filters.SimplePatternFileListFilter">
<beans:constructor-arg value="${pattern}" />
</beans:bean>
<beans:bean id="compositeFileFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<beans:constructor-arg>
<beans:list>
<beans:ref bean="antPatternFileFilter" />
<beans:ref bean="persistentAcceptOnceFileFilter" />
</beans:list>
</beans:constructor-arg>
</beans:bean>
<file:inbound-channel-adapter
auto-startup="false"
channel="file" directory="${dir}" filter="compositeFileFilter">
<poller fixed-delay="${fixedDelay}" time-unit="SECONDS"/>
</file:inbound-channel-adapter>
<channel id="file"/>
<chain id="extractContents" input-channel="file" output-channel="output">
<header-enricher>
<header name="contentType" value="application/octet-stream"/>
</header-enricher>
<file:file-to-bytes-transformer/>
</chain>
<channel id="output"/>
The problem I am having is that should the redis container go down, persistentAcceptOnceFileFilter will throw exceptions whenever it is invoked, landing them in the errorChannel.
Unfortunately, within my organization, all messages posted in the errorChannel are picked up by a service that emails the team and posts a trouble ticket in our ticketing system, meaning that if redis ever goes down in the night, our ticketing system will get pummeled with tens of thousands of messages that some poor team member will have to go through and close.
To get around this problem, I thought of extending the FileSystemPersistentAcceptOnceFileListFilter with error handling so that, instead of hitting the error channel, we simply refuse all files detected and leave message in the xd-container log, but this is a solution that I do not prefer because I'd like to solve this problem entirely through configuration and without circumventing our ticketing/notification system entirely. Instead I would prefer to allow a single send to the errorChannel (so we get one notification/ticket) and then stop the stream this module is a component of (or at least, something functionally equivalent, preferably via configuration). Is there a way to do this?
Upvotes: 1
Views: 235
Reputation: 174719
Since I don't see a custom error-channel
, I assume your ticket system is driven from the logging subsystem (via the default errorChannel
and its logging handler subscriber).
Since the default errorChannel
is a pub/sub, you can subscribe a second flow to it...
<int:transformer input-channel="errorChannel" expression="@fileChannelAdapter.stop()"
output-channel="control" />
<int:control-bus input-channel="control" />
And set id="fileChannelAdapter"
on the file channel adapter.
Upvotes: 1