Announcement Announcement Module
Collapse
No announcement yet.
What should I use for synchrounous send and receive method. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What should I use for synchrounous send and receive method.

    I'm stuck implementing an interface from the business layer that looks something like this "XResponsefx(XRequest)".

    Inside fx call
    public XResponse fx(XRequest) {
    channel.send(new GenericMessage(XRequest))
    ..... /* The part I'm blanking on */
    return XResponse

    }

    I'm using a chain to send the XRequest through the input channel to a transformer, header enricher and an int-ws:outbound-gateway that sends the output-channel to a transformer the gives me the XResponse

    But how do I get the payload off of the response channel so I can return that from XResponse? I thought I could use a service-activator, but I now realize that won't work for the synchronous requirement.
    Am I supposed to use a channel adapter to get the response channel payload?
    I will continue to search this form for the answer, but there's only 192 some pages to wade through find, and I'm hoping someone can provide answer faster than I can hunt it down.

  • #2
    Hello

    How about this one: http://static.springsource.org/sprin...r.html#gateway ?

    Take care,
    Artem

    Comment


    • #3
      Thanks. I will experiment with that.
      I did consider using a pollable channel for the response channel, but this looks like a better solution.

      Comment


      • #4
        I've created the <int:gateway> but I'm don't know how to tie the gateway to the chain where the real work gets done.
        I want the gateway to send it's payload to the chain, and the chain to return the results to the gateway. I'll read the documentation more closely, but if someone already knows the answer I'd appreciate hearing about it.

        <int:gateway id="serviceGateway" default-request-channel="requestChannel" default-reply-channel="responseChannel" service-interface="a.b.service.SomeService" default-reply-timeout="15" default-request-timeout="15">
        <int:method name="fx"/>
        </int:gateway>

        <int:chain input-channel="requestChannel" output-channel="responseChannel">
        <int:transformer ref="transformer"/>
        <int-ws:header-enricher>
        <int-ws:soap-action value="#{soapActions['blah']}"/>
        </int-ws:header-enricher>
        <int-ws:outbound-gateway destination-provider="destinationProvider"
        unmarshaller="marshaller" marshaller="marshaller"/>
        <int:transformer ref="transformer"/>
        </int:chain>

        Comment


        • #5
          Hello

          The first: please, use the [ CODE ] & [ /CODE ] or [ HTML ] & [ /HTML ] for wrapping your samples in the post.

          Now what I see in your config: everything looks good.
          Invocation on the serviceGateway#fx() initiates an message flow through requestChannel and this flow makes reply into
          responseChannel. What's going on inside this "black box", doesn't matter .
          As I understand now you have a question how to invoke your gateway. It can be done several point:
          as bean injection into some your service as <service-activator>'s method-invocation.

          Is it what are you looking for?

          By the way: if your message flow so simple, maybe there is no any reason to use 'reply-channel' on the <gateway> and remove 'output-channel' on the <chain>. Gateway's method with non-void return inject into 'reply-channel' messageHeader some TemporaryReplyChannel instance and it will be enough to have classic request-reply message flow.

          Cheers

          Comment


          • #6
            Originally posted by Cleric View Post
            By the way: if your message flow so simple, maybe there is no any reason to use 'reply-channel' on the <gateway> and remove 'output-channel' on the <chain>. Gateway's method with non-void return inject into 'reply-channel' messageHeader some TemporaryReplyChannel instance and it will be enough to have classic request-reply message flow.
            I'm not sure what to make of this. Think it means I need to do something like this:
            Code:
            <int:gateway id="serviceGateway" default-request-channel="requestChannel" service-interface="a.b.service.SomeService">
                <int:method name="fx">
                    <int:header name="replyChannel" value=responseChannel"/>
                </int:method>
            </int:gateway>
            I've tried this without any changes to the chain, but I get "org.springframework.integration.MessageDeliveryEx ception: Dispatcher has no subscribers for channel responseChannel".

            One key concept that I don't understand is how the gateway feeds into the chain, and I obviously don't know what my responseChannel is doing.

            I don't have a service activator on the end of the chain, and I'm wondering if that is part of the problem. The last transformer at the end of the chain produces that output that I want returned from serviceGateway#fx().
            I've looked at an example that uses a gateway to send stuff directly to a service activator and gets a return value, but the "service activator" I'm trying to use is the chain.

            Comment


            • #7
              You don't even need to add that replyChannel header explicitly. The gateway will automatically add one by default, and then the terminal downstream component that has no explicit output-channel will then send to that auto-created one. In your case if the ultimate downstream component is actually the chain itself, that means you can remove its 'output-channel' attrib altogether.

              Hope that's clear.
              -Mark

              Comment


              • #8
                Here's why I am getting hung up on the replyChannel. The log shows that it makes it through the last transformer at the end of the chain, and sends the x.y.z.XReponse back to the serviceGateway, but the gateway carps about no replyChannel header available.

                Code:
                2012-08-16 08:14:10,598 [main] DEBUG org.springframework.integration.transformer.MessageTransformingHandler - handler 'org.springframework.integration.transformer.MessageTransformingHandler@164cbde' sending reply Message: [Payload=x.y.z.XResponse@1de8aa8][Headers={timestamp=1345122850598, id=4aa38bc5-4df9-4cc1-ad8b-b0f15d2b35c8}]
                2012-08-16 08:14:10,598 [main] WARN  org.springframework.integration.gateway.GatewayProxyFactoryBean$MethodInvocationGateway - failure occurred in gateway serviceGateway
                org.springframework.integration.MessageHandlingException: no replyChannel header available
                	at org.springframework.integration.handler.MessageHandlerChain$ReplyForwardingMessageChannel.send(MessageHandlerChain.java:214)
                	at org.springframework.integration.handler.MessageHandlerChain$ReplyForwardingMessageChannel.send(MessageHandlerChain.java:203)
                	at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288)
                	at org.springframework.integration.core.MessagingTemplate.send(MessagingTemplate.java:149)
                	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendMessage(AbstractReplyProducingMessageHandler.java:175)
                	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.sendReplyMessage(AbstractReplyProducingMessageHandler.java:159)
                	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.produceReply(AbstractReplyProducingMessageHandler.java:124)
                	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleResult(AbstractReplyProducingMessageHandler.java:118)
                	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:100)
                	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73)
                	at org.springframework.integration.handler.MessageHandlerChain$1.send(MessageHandlerChain.java:154)

                Comment


                • #9
                  Hello

                  Let me gues: your transformer bean returns entire Message and you don't copy request headers to that Message on its build.
                  <transformer> is a component with some specific contract: it is an Black Box for framework and what he takes and returns is up to end-developer. And the returned Message will be sended to the output-channel or reply-header-channel (if available ) without any modifications.

                  So, now question from me: what does your transformer bean do?

                  Comment


                  • #10
                    To further clarify; we generally recommend user code to NOT use the messaging APIs directly - in the vast majority of cases, you should use POJOs and not depend on Message<?> etc directly.

                    See this thread for some further insight...

                    http://forum.springsource.org/showth...cement-request

                    Comment


                    • #11
                      Here it is in all of its glory.
                      Code:
                      public class MyTransformer implements Transforme {
                      
                        public Message<?> transform( final Message<?> message ) {
                          Object payload = message.getPayload();
                          Message<?> forwardMessage;
                      
                      if ( payload instanceof ThingThatWrapsMyRequestAndMyResponseTypes ) {
                            // create JAXB request object from our data type
                            // this goes into the int-ws:outbound-gateway
                            ThingThatWrapsMyRequestAndMyResponseTypes x = (ThingThatWrapsMyRequestAndMyResponseTypes)payload;
                            JAXBWebServiceRequestType y = new JAXBWebServiceRequestType();
                            // stuff some values from x into y
                            forwardMessage = new GenericMessage<JAXBRequestType>( y );
                          } else
                          if ( payload instanceof JAXBWebServiceResponse ) {
                            // Transform the JAXB response to out data type
                            // this goes back to the int:gateway "serviceGateway"
                           JAXBObject x = (JAXBObject)payload;
                           ThingThatWrapsMyRequestAndMyResponseTypes y = new ThingThatWrapsMyRequestAndMyResponseTypes();
                           // stuff some values from x into y
                            forwardMessage = new GenericMessage<ThingThatWrapsMyRequestAndMyResponseTypes>( y );
                          }
                          else {
                            // this is probably a half-baked idea
                            forwardMessage = new GenericMessage<AssertionError>(
                                new AssertionError( ERROR_MSG + payload.getClass() ) );
                          }
                          return forwardMessage;
                        }
                      }

                      Comment


                      • #12
                        I changed my Transformer to an AbstractTransformer, and changed my method to doTransform that returns the pojos, and it worked.

                        You have a potential source of revenue at your fingers. I would like to see a book that puts more emphasis on the classes such as AbstractTransformer that don't require the developer to mess with the Message.

                        I have just searched Spring Integration in Action, Pro Spring Integration, and the Sprint Integration Reference Manual, and AbstractTransformer was only mentioned in the reference manual once.
                        The books and examples I have found all emphasis the nitty gritty at the Message level and not the POJO level.

                        Thank you all for your help.

                        Comment

                        Working...
                        X