Announcement Announcement Module
Collapse
No announcement yet.
Spring Integration Programmatically create Channer Adapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Integration Programmatically create Channer Adapter

    Hi,

    I want to create multiple instances of ImapChannerlAdapter. I cannot configure each statically in the context file, and have to do it programmtically (because there can be many inboxes). Apart from ImapChannerlAdapter rest of the configuration of channels, chains etc will be in config file. So the adapter picks the email and send it to channel configured in the xml.

    Please assist how to do that.

    I tried with the code below, but i dont know how to set trigger interval on TaskScheduler. And am i doing it correctly.

    ImapIdleChannelAdapter channelAdapter = null;
    ImapMailReceiver mailReceiver = null;
    try {
    mailReceiver = new ImapMailReceiver("imaps://user1%[email protected]:993/INBOX");
    mailReceiver.setJavaMailProperties(props);
    mailReceiver.setJavaMailAuthenticator(new Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("admin", "adminpassword");
    }
    });
    mailReceiver.setShouldDeleteMessages(false);
    mailReceiver.setShouldMarkMessagesAsRead(false);

    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.setPoolSize(5);

    channelAdapter = new ImapIdleChannelAdapter(mailReceiver);
    channelAdapter.setShouldReconnectAutomatically(tru e);
    channelAdapter.setTaskScheduler(taskScheduler);
    channelAdapter.setOutputChannel(applicationContext .getBean("DirectChannel"));
    channelAdapter.start();
    } catch (IllegalStateException ise) {
    ise.printStackTrace();
    if (channelAdapter != null) {
    channelAdapter.stop();
    try {
    mailReceiver.destroy();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    Here i have following configuration in the xml
    DirectChannel --> chain --> etc

    Thanks
Working...
X