Results 1 to 6 of 6

Thread: How to read messages from a queue channel inside a service-activator?

  1. #1
    Join Date
    Jul 2010
    Posts
    8

    Default How to read messages from a queue channel inside a service-activator?

    I'm trying to read messages from a queue channel inside a service-activator. I know how to read these messages in the main thread (i.e. where the applicationContext is initialized), where I could just get the instance of the channel and then call the receive method. The problem is that inside the service activator I don't have access to the applicationContext...
    Can someone halp me solve this problem?
    Thanks a lot.

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

    Default

    All you need is a poller configured in service-activator. The poller will poll for messages from the queue.

    Code:
    <service-activator input-channel="someQueueChannel"
            output-channel="output">  
         <poller receive-timeout="30000">
             <interval-trigger interval="10"/>
         </poller>
     </service-activator>
    Just do a string search in the documentation for 'poller', there are plenty of samples.

  3. #3
    Join Date
    Jul 2010
    Posts
    8

    Default

    The service activator I was talking about is already receiving messages from a direct channel.
    Now, I want, when the service activator receives a message from the direct channel, to read all messages from the queue channel, then modify the message received from the direct channel and send it out on the output-channel.

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,844

    Default

    You can always inject the channel instance into the service object that you are invoking through the service activator using standard DI.

    However, could you provide a bit more detail about the use-case? Specifically, what is contained in the Message that is received from the DirectChannel? Is that only being used as a trigger to drive the polling consumer?

  5. #5
    Join Date
    Jul 2010
    Posts
    8

    Default

    Problem solved.

    I've just injected the queue-channel inside the service-activator....

    Thanks a lot again.

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

    Default

    Glad to hear you have a working solution. However, can you please describe the use-case? It sounds like it might be solvable in a different way... or at least something that we could address in 2.0. In most cases, your service object should not even be aware of the messaging API.

    Thanks,
    Mark

Posting Permissions

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