Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Programmatically invoking si:inbound-channel-adapter (SourcePollingChannelAdapter)

  1. #1
    Join Date
    May 2009
    Posts
    6

    Default Programmatically invoking si:inbound-channel-adapter (SourcePollingChannelAdapter)

    Hi,

    I have this:

    <inbound-channel-adapter id="myAdapter" ref="someBean" method="getSomething" channel="someChannel" >
    <poller>
    <interval-trigger interval="12345" time-unit="SECONDS"/>
    </poller>
    </inbound-channel-adapter>

    This serves as a 'trigger' for some long process (someBean.getSomething() returns some data based on which a long execution begins.

    I want to initate the same process programmatically, reusing as much code as possible.
    I was hoping to find a context.getBean("myAdapter").poll(), but couldnt.

    Does SourcePollingChannelAdapter expose such capabilities?

    What's the best way to do something like this ?

    * I'm using 1.0.1

    10x,
    Ido

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    As part of SI 2.0 M1 we have a MessagePublisher which would allow you to invoke a method on any bean and have the result of such invocation be sent to a designated message channel:
    http://static.springsource.org/sprin...age-publishing
    Could you upgrade?

  3. #3
    Join Date
    May 2009
    Posts
    6

    Default

    Thanks, Oleg.

    Actually, upgrading to a milestone version is not that possible at the moment - we are nearing our deadline, and that could be problematic.

    Any other ideas, using 1.0.x ?

    Thanks again,
    Ido

  4. #4
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    614

    Default

    Why not just invoke someBean.getSomething? All the reuse that would miss there is code that is not in your repository anyway.

  5. #5
    Join Date
    May 2009
    Posts
    6

    Default

    because i would be losing logic that is found inside SourcePollingChannelAdapter, like polling more than once, etc.

  6. #6
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    If you are able to upgrade to Spring 3.0, then you might want to look at the new "task" namespace and @Scheduled annotation support. In both cases, you can register a simple ref/method combination along with a "trigger" for scheduling (fixed-rate, fixed-delay, or cron). As of Spring Integration 2.0, that is the same basic mechanism used behind the scenes.

    If you still see limitations with that approach, let us know, since we are considering some form of event-driven triggering in 2.0. It would be great to get specific feedback on that requirement.

    Thanks,
    Mark

  7. #7
    Join Date
    Jun 2010
    Posts
    5

    Default Programmatically invoking si:inbound-channel-adapter

    Hey guys,

    I seem to be having an issue with the inbound-channel-adaptor. My setup is very basic. I've created a few classes and then an integration context file to wire it all together. The whole thing is just running in a main function that I threw together.

    I've tried to add a poller to my inbound-channel-adaptor, but my method never gets called. I also tried to invoke this method from the main function and it still does not pass along my message to the intended channel. I can see that it has gotten into the method due to the fact that it spits out a log message.

    I created a gateway to pass along the same object to the same channel and it works fine. Not sure at all what I'm doing wrong. I believe I've done everything properly. I'm using the latest spring and spring integration.

    Here's my integration context XML file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--/*
    */
    -->
    
    <beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:si="http://www.springframework.org/schema/integration"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
        ">
    
        <beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <beans:property name="location" value="classpath:integrationsContext.properties"/>
            <beans:property name="ignoreUnresolvablePlaceholders" value="true"/>
        </beans:bean>
    
        <si:channel id="vendorEventsIn"/>
        <si:channel id="smsEventsIn"/>
        <si:channel id="smsEventsOut"/>
        <si:channel id="vendorEventsOut"/>
        
        <!-- need this? -->
        <si:gateway id="eventGateway" default-request-channel="vendorEventsIn"
                    default-reply-channel="vendorEventsOut" service-interface="gateway.gateway.TestGateway" />
    
        <si:inbound-channel-adapter ref="vendorHandler" method="checkForUpdates" channel="vendorEventsIn">
            <si:poller>
               <si:interval-trigger interval="1000"/>
            </si:poller>
        </si:inbound-channel-adapter>
    
        <si:transformer input-channel="vendorEventsIn"
            ref="vendorToSmsTransformer" method="transform" output-channel="smsEventsIn" />
    
    
        <si:service-activator ref="smsWsClient" method="forwardSmsEvent" input-channel="smsEventsIn" output-channel="smsEventsOut"/>
        
        <si:transformer input-channel="smsEventsOut" ref="smsToVendorTransformer" 
                        method="transform" output-channel="vendorEventsOut" />
                        
    
        <si:outbound-channel-adapter ref="vendorHandler" method="reply" channel="vendorEventsOut"/>
    
    
        <beans:bean id="vendorHandler" class="gateway.vendor.TestVendorHandler" />
        <beans:bean id="vendorToSmsTransformer" class="gateway.transformer.TestVendorToSmsTransformer" />
        <beans:bean id="smsToVendorTransformer" class="gateway.transformer.TestSmsToVendorTransformer" />
        <beans:bean id="smsWsClient" class="gateway.sms.SmsWsClient" />
    
    
        <si:poller max-messages-per-poll="1" id="defaultPoller" default="true">
            <si:interval-trigger interval="3000"/>
        </si:poller>
    
    </beans:beans>
    Here's my method being called in the class:
    Code:
        public Message<?> checkForEvents()
        {
            // TODO Auto-generated method stub
            LOGGER.info("checking for events");
            Message<?> response = null;
            
            TestEvent e = new TestEvent();
            e.setId(1L);
            
            response = MessageBuilder.withPayload(e).build();
    
            return response;
        }
    I've also tried this with just the object I wanted to send along to the channel. Still, no luck.

    Finally, this is me trying to invoke the thing in my main class:
    Code:
    public static void main(String[] args)
    {
            try
            {
                ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] { "integrationsContext.xml" });
    
                appContext.start();
    
                // works!!!!
                //TestGateway tg = (TestGateway)appContext.getBean("eventGateway");
                //tg.testIt(new TestEvent());
                
                // does not work 
                TestVendorHandler tvh = (TestVendorHandler)appContext.getBean("vendorHandler");
                tvh.checkForEvents();
            }
            catch (Throwable e)
            {
                LOGGER.info(ExceptionUtils.getFullStackTrace(e));
            }
        }
    Last edited by roadblocked; Jun 22nd, 2010 at 09:30 AM.

  8. #8
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    The inbound-channel-adapter is intended to be used as a scheduled, background polling mechanism. If you call that method yourself (like you do in the main() method), then it's just a normal method call on that object. In your configuration, however, you have a poller that should also be invoking that method in the background every 3 seconds and sending the return value (if not null) to the 'vendorEventsIn' channel.

    If you actually want a Message to be published as the by-product of a method call, then you should use our AOP interceptor *instead of* an inbound-channel-adapter. Read this for an overview: http://static.springsource.org/sprin...age-publishing

  9. #9
    Join Date
    Jun 2010
    Posts
    5

    Default

    Mark,

    My intent is to use the poller to call the channel adaptor, but I thought I had a problem so I tried to invoke it directly and see what happened there. I'm still not sure what to think about why that inbound-channel-adaptor wasn't working for me.

    I'll check out the publishing section of the reference manual that you have provided. Looks like it may come in handy down the line.

    Thanks for the fast reply.

  10. #10
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    One thing that might help is to temporarily add a wiretap for debugging purposes:
    Code:
    <channel id="processingChannel">
        <interceptors>
            <wiretap channel="wiretapChannel"/>
        </interceptors>
    </channel>
    Probably the simplest thing is to use a logging-channel-adapter along with that:
    Code:
    <logging-channel-adapter id="wiretapChannel"/>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •