Results 1 to 6 of 6

Thread: Simple gateway request to datastore question

  1. #1
    Join Date
    Jul 2012
    Location
    Denver metro
    Posts
    18

    Default Simple gateway request to datastore question

    I'm trying to do something simple, but can't seem to get it to work. The use case is something like this:

    I want to send a quick rest call to trigger an event into a spring route, that event creates a new object and then writes that to a JMS queue (processed by another system in order to separate a long-running process). The created object that is enqueued should then returned to the web service. In this case it's a JMS queue, but it could be any datastore (db, file, email, etc)

    Example: (Ignoring the whole REST portion - just looking at the route which is outwired in via the inbound gateway)

    Code:
      <int:gateway id="inboundGateway" service-interface="com.readytalk.springInt.endpoint.FooGateway" 
          default-request-channel="fromFooGateway" />
    
      <int:channel id="fromFooGateway" />
    
      <int:service-activator input-channel="fromFooGateway" ref="testServiceActivator" method="createObject" 
         output-channel="postCreateChannel" />
    
      <int:channel id="postCreateChannel" />
      
      <int-jms:outbound-channel-adapter channel="postCreateChannel" destination-name="toProcessQueue" 
         connection-factory="jmsConnectionFactory"/>
    Now, this route is obviously wrong because the jms outbound channel adapter doesn't return anything, so the inbound gateway hangs indefinitely. So, what's the 'right' way to do what I'm looking for? Send a message down the route and then get it back once it is successfully persisted at the end of processing.

    I know that I could create a service-activator and write to the queue with JmsTemplate, but that seems like a lot of code to do something that the framework can usually handle.

    -- Note: This came up as we started looking at error handling using gateways to create 'error segments' as shown by Oleg during one of his spring tips and tricks. Our error handling route was going to write an error message to the database, but that was causing the thread to hang waiting for a reply that was never coming.
    Last edited by mgirard; Jul 19th, 2012 at 03:19 PM.

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

    Default

    You can add a publish-subscribe-channel in front of the jms outbound-gateway. As long as you do not make it async (don't add a task-executor), then you can control the order of subscribers (using the 'order' attribute) and therefore add order='2' on some simple transformer or something similar after the jms outbound-gateway containing order="1"

    Does that make sense?

  3. #3
    Join Date
    Jul 2012
    Location
    Denver metro
    Posts
    18

    Default

    So all subscribers are executed sequentially based on the order, and if the first one fails an error is bubbled back up the chain (to the gateway)? Otherwise the 2nd subscriber will execute, and so on...

    Right?

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

    Default

    THat's correct, but as Mark stated only in the cases of sync pub-sub

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

    Default

    There is actually a config option (the 'ignore-failures' attribute on the publish-subscribe-channel) that allows you to avoid that "bubbling up" you mentioned and continue invoking subscribers, but I have a feeling you do want errors to short-circuit, right?

  6. #6
    Join Date
    Jul 2012
    Location
    Denver metro
    Posts
    18

    Default

    In most normal-flow cases I do want that error to come back, but it's nice to have the option. Now it's back to work...

    Thank you both for the quick response!

Posting Permissions

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