Results 1 to 4 of 4

Thread: How can I change the twitter query for a search-inbound-channel-adapter?

  1. #1
    Join Date
    Oct 2012
    Posts
    3

    Default How can I change the twitter query for a search-inbound-channel-adapter?

    Hi, I'm very new to Spring Integration... I'm using STS, and I created a Spring Template Project, the Spring Integration Project (War) twitter example. It contains the following in spring-integration-context.xml

    Code:
        <int-twitter:search-inbound-channel-adapter
    		id="twitter" query="#springintegration"
    		channel="twitterChannel" auto-startup="false">
    		<int:poller fixed-rate="5000" max-messages-per-poll="10" />
    	</int-twitter:search-inbound-channel-adapter>
    How can I programatically change the twitter query on the fly for this channel adapter ?

    (I'm using the standard DefaultTwitterService that is generated)

    Thanks for your time,
    Erich

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,147

    Default

    The twitter adapter does not currently (via configuration) support a variable search query.

    Seems like a reasonable improvement to use a SpEL expression - please open a JIRA ticket...

    https://jira.springsource.org/browse/INT

    You can do it programmatically, though; get a reference to the SourcePollingChannelAdapter bean named 'twitter' in your example; and use reflection to get the SearchReceivingMessageSource (in the source field). You can then call setQuery() and the new query will be used on the next poll.

    Spring provides a DirectFieldAccessor to conveniently get a reference to the source field.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Aug 2005
    Location
    Atlanta
    Posts
    124

    Default

    Hi,

    Just FYI - We have an open issue regarding providing Twitter Outbound Gateways, which would allow you to trigger Twitter operations using command messages.

    https://jira.springsource.org/browse/INT-1939

    However, it would not cover SpEL expression support, which in your case might be the more desired approach.

    Without using reflection, you also have have option to pass a new 'SearchReceivingMessageSource' into the 'PollingChannelAdapter':

    Code:
    @Autowired
    @Qualifier("twitterSearch")
    private SourcePollingChannelAdapter sourcePollingChannelAdapter;
    ...
    SearchReceivingMessageSource source = new SearchReceivingMessageSource(twitterTemplate);
    source.afterPropertiesSet();
    source.setQuery("#springintegration");
    sourcePollingChannelAdapter.setSource(source);
    ...
    Cheers,

    Gunnar
    Gunnar Hillert
    SpringSource/VMWare, Spring Integration team
    SpringSource Team - Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/ghillert
    http://blog.hillert.com/
    http://blog.springsource.com/author/ghillert/

  4. #4
    Join Date
    Oct 2012
    Posts
    3

    Default

    Thanks Gary and Gunnar, your responses were very helpful.

    I was able to achieve what I was looking to do through both of your suggestions.

    I have logged INT-2789 for the addition of SpEL config for the twitter adapter query.

    Thanks,
    Erich

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
  •