Announcement Announcement Module
Collapse
No announcement yet.
How can I change the twitter query for a search-inbound-channel-adapter? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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

      Comment


      • #4
        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

        Comment

        Working...
        X