Возникшие проблемы при реализации функции постепенного отключения - PullRequest
0 голосов
/ 13 июня 2019

Я работаю над автономным приложением весенней загрузки и использую архитектуру канала интеграции с пружиной для передачи файлов из источника в место назначения.Мы также предоставили функцию нескольких экземпляров, для достижения которой мы будем блокировать (добавлять .lock для файлов) файлы для конкретного экземпляра, чтобы ограничить доступ из другого экземпляра.В настоящее время у меня есть одно требование для постепенного отключения.Я реализовал, но в конечном итоге со следующей ошибкой.Кто-нибудь может мне помочь в этом?

Control bus configuration :

<integration:channel id="controlChannel" />
<integration:control-bus input-channel="controlChannel" />

Adapter configuration :

<file:inbound-channel-adapter id="filesInChannel"
        directory="path" auto-startup="false" scanner="recursiveScanner"
        auto-create-directory="true">
        <integration:poller id="poller"
            max-messages-per-poll="5" fixed-rate="1000" 
            task-executor="pollingExecutor">
            <integration:transactional
                transaction-manager="transactionManager" />
        </integration:poller>
    </file:inbound-channel-adapter>

Method added for graceful shutdown component
@PreDestroy
    public void onDestroy() throws InterruptedException {

        try {
            inboundFileAdapterChannel.send(new GenericMessage<String>("@'filesInChannel.adapter'.stop()"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        // wait till current processing of files is over
        pollingExecutor.shutdown();
        pollingExecutor.setWaitForTasksToCompleteOnShutdown(Boolean.TRUE);
        System.out.println("Application shutdown succesfully");
    }

Ошибка трассировки:

org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.controlChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=@'filesInChannel.adapter'.stop(), headers={id=5f0282c5-5a02-3f57-3056-948dd74a8d72, timestamp=1559894703464}], failedMessage=GenericMessage [payload=@'filesInChannel.adapter'.stop(), headers={id=5f0282c5-5a02-3f57-3056-948dd74a8d72, timestamp=1559894703464}]
        at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
        at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:445)
        at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:394)
        at com.openbank.interfaces.file.handler.GracefulShutdownHook.onDestroy(GracefulShutdownHook.java:63)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:365)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeDestroyMethods(InitDestroyAnnotationBeanPostProcessor.java:323)
        at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeDestruction(InitDestroyAnnotationBeanPostProcessor.java:155)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:240)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:577)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:549)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:957)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:510)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:964)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1041)
        at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1017)
        at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:937)
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=@'filesInChannel.adapter'.stop(), headers={id=5f0282c5-5a02-3f57-3056-948dd74a8d72, timestamp=1559894703464}]
        at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:138)
        at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
        at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
        ... 19 more

1 Ответ

1 голос
/ 13 июня 2019

@PreDestroy слишком поздно для выполнения таких операций.

К этому времени все компоненты Lifecyle будут stop() ped (что отписывается от канала).

Вы должны выполнить эту работу, используя другой сигнал.

Вы можете реализовать SmartLifecyle и перевести ваш бин в позднюю фазу (так что stop() ped рано.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...