Announcement Announcement Module
Collapse
No announcement yet.
Inject request scoped twitter-template bean into twitter inbound-channel-adapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inject request scoped twitter-template bean into twitter inbound-channel-adapter

    Hi,

    I have an annotation configured request-scoped TwitterTemplate bean and I want to inject that bean into an xml configured inbound-channel-adapter.

    What is the best way to do that and are there any implications that need to be considered in case of multiple sessions accessing the same inbound-channel-adapter?

    Are there any examples of twitter inbound-channel-adapter configured through java?

  • #2
    Hi!

    request-scoped into inbound-channel-adapter
    You can't do it at all. All Twitter inbound-channel-adapters produce Polling Endpoint: http://static.springsource.org/sprin...lling-consumer.
    You need configure some TaskScheduler, Trigger and allow to 'poll' Twiiter for some AbstractTwitterMessageSource implementation.
    So, in this scenario you can't access to the request thread.

    Explain, please, your use-case: maybe there is another solution.

    Take care,
    Artem

    Comment


    • #3
      Hi and thanks for the reply.

      Originally posted by Cleric View Post
      Explain, please, your use-case: maybe there is another solution.
      My use case is an app which serves more than one twitter profiles. So I have a TwitterTemplate bean bound to the current user and I want to poll twitter for messages from the user's timeline.

      From the Spring Integration manual I can see that one can simply inject twitter-template="twitterTemplate" like this:

      <int-twitter:inbound-channel-adapter
      twitter-template="twitterTemplate"
      channel="inChannel">
      <intoller fixed-rate="5000" max-messages-per-poll="3"/>
      </int-twitter:inbound-channel-adapter>


      My TwitterTemplate bean is annotation configured and request scoped though.

      Comment


      • #4
        Why haven't you made any comment about my multithreading explanation?
        How do you plan to put twitts to the response?
        Maybe it will be enough just to invoke TwitterTemplate directly:
        Code:
        TwitterTemplate.directMessageOperations().getDirectMessagesReceived
        ?

        Comment


        • #5
          Hi,

          What is exactly your use-case? It looks like you have users (per request) that may want to actively reach out to Twitter and perform a search, is that correct? If that is the case, we have an open Jira for a Twitter Outbound Gateway:

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

          This would allow you to actively perform Twitter operations such as searching without terminating the Spring Integration flow or having to use a poller.

          Cheers,

          Gunnar

          Comment


          • #6
            Right - request scope only works for container-managed threads. By definition, the poller uses its own threads.

            Artem's solution should work because it will run on the container's thread. You can then send the tweets to an integration flow using a <gateway/>.

            But, the <outbound-gateway/> will be a nice addition.

            Comment


            • #7
              Hi, all!

              Gary, can we somehow use here WebSocket extension, e.g. in case, if we want to have 'push' scenario in the our web-page with scoped TwitterTemplate?

              Comment


              • #8
                Perhaps, but request scope still won't work there. You'd still need to use your technique.

                Also, not all browsers support websockets yet.

                Comment


                • #9
                  What is exactly your use-case? It looks like you have users (per request) that may want to actively reach out to Twitter and perform a search, is that correct?
                  Yep... multiple twitter users, polling their timelines periodically and apply some kind of a service activator on the flow of messages.

                  Sorry guys that I am not expressive enough but started reading up on Spring Integration yesterday.

                  Comment

                  Working...
                  X