1
votes

Messaging exception: org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.web.context.WebApplicationContext:/.sftpChannel'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers

I am trying to send file from local to remote server.

My application context is below

 <bean id="startupBean" class="com.SchedulerImpl" init-method="run"/>
 <bean id="applicationContextProvider" class="com.ApplicationContextProvider"></bean>

 <bean id="sftpSessionFactory" class="org.springframework.integration.file.remote.session.CachingSessionFactory">
    <constructor-arg ref="defaultSftpSessionFactory" />
</bean>
    <bean id="defaultSftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
        <property name="host" value="${destination.host}"/>
        <property name="privateKey" value="${destination.privateKey}"/>
        <property name="privateKeyPassphrase" value="${destination.privateKeyPassphrase}"/>
        <property name="port" value="${destination.port}"/>
        <property name="user" value="${destination.user}"/>
        <property name="sessionConfig" ref="props"/>
    </bean>

     <util:properties id="props">
            <prop key="PreferredAuthentications">publickey</prop>
        </util:properties>  
    <int:channel id="sftpChannel"/>

    <int-sftp:outbound-channel-adapter id="sftpOutboundAdapter" 
                                        session-factory="sftpSessionFactory"
                                        channel="sftpChannel" 
                                        auto-startup ="false"
                                        charset="UTF-8" 
                                        remote-directory="/destinationFolder/"
                                        remote-file-separator="/">
     </int-sftp:outbound-channel-adapter>

     <int:publish-subscribe-channel id="contextRefreshEvents"/>

     <int:outbound-channel-adapter channel="contextRefreshEvents"
                            expression="sftpOutboundAdapter.start()" />

so I get same instance of applicationContext inside code of sftp class as:

ApplicationContext context = appContext.getApplicationContext();

MessageChannel sftpChannel = (MessageChannel)context.getBean("sftpChannel");

and @Autowired private ApplicationContextProvider appContext; inside same sftp class.

there's another class ApplicationContextProvider which implements ApplicationContextAware which helps me to get current ApplicaitonContext.

I dont understand why I get No subscriber found. I have put auto-startup=false. what would be correct way of getting current sftpChannel bean which gives me same instance of applicationContext.

If I do appContext = new classpathxmlapplicationcontext(applicationcontext.xml ) I get error in startupBean, so I dont want to do that.

Now I am implementing ApplicationContextAware, and I get Messaging exception.

could anyone please help me out?

I am using spring 3

1

1 Answers

0
votes

You have shared a lot from your mind and in the end your question becomes in a mess.

From other side let me explain what's going on.

Since you have auto-startup ="false" on the <int-sftp:outbound-channel-adapter>, any send to the sftpChannel will cause that Exception until you start that adapter.

From other side I see you do that, although we don't see who initiates contextRefreshEvents messages, but we believe you that it is <int-event:inbound-channel-adapter>.

And one more point here that you don't show us that file from local. OK, I guess it is <int-file:inbound-channel-adapter>. Which is pollable and starts to poll the local director just after application start up. So, that may cause Dispatcher has no subscribers, because sftpOutboundAdapter hasn't been started yet.

Let me know, if I went wrong way in my reasoning, but you expected something different.

UPDATE

To start endpoint (or any other Lifecycle component) programmatically you should inject it to your service:

@Autowired
@Qualifier("sftpOutboundAdapter")
private Lifecycle sftpOutboundAdapter;

....

sftpOutboundAdapter.start();