Announcement Announcement Module
Collapse
No announcement yet.
Simple gateway request to datastore question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 04:19 PM.

  • #2
    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?

    Comment


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

      Comment


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

        Comment


        • #5
          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?

          Comment


          • #6
            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!

            Comment

            Working...
            X