Skip to content

Allow Gateway to return information about the message status [INT-943] #4959

Closed

Description

@spring-operator

Dave Syer opened INT-943 and commented

Allow Gateway to return information about the message status. Currently the only interpretation for a return value from a gateway interface in GatewayProxyFactoryBean is that the caller requires a reply. That's nice as a default, but sometimes you just want an ACK or maybe one of the message headers from the message that was sent. Maybe some additional declaration in the XML would work, e.g.:

<gateway id="fileSender" service-interface="...FileSender"
		default-request-channel="input-files" return-value="headers.'$timestamp'"/>

What I was hoping for was a way to declare that a boolean return type should be interpreted as an ACK/NACK (true/false). Maybe that use case is irrelevant anyway, i.e. if the gateway only returns successfully if the message was sent - the contract of the MessagingGateway is not very clear.


Affects: 2.0 M2

Issue Links:

Activity

  1. spring-operator commented on Dec 23, 2009

    @spring-operator
    ContributorAuthor

    Mark Fisher commented

    We do need to support more options for return value handling in the gateway. I think we might want to simply re-use the annotations (@Payload/@Header/@Headers) that are currently used on parameters, but at method-level, they would be applied to the return value (similar to @MVC).

    Thoughts?

  2. spring-operator commented on May 6, 2010

    @spring-operator
    ContributorAuthor
  3. spring-operator commented on Jun 24, 2010

    @spring-operator
    ContributorAuthor

    Mark Fisher commented

    I've been thinking about this one a bit, and I'm not very comfortable with the looseness of the current "contract". The idea that void means one way and no-args means receive() (rather than say... send some message generated by a SpEL expression, see: https://jira.springsource.org/browse/INT-670) seems a bit shaky. I think we can have some defaults, but we should probably enable configuration of things like whether we're expecting a reply, sending or receiving when no args, etc.

  4. spring-operator commented on Jun 28, 2010

    @spring-operator
    ContributorAuthor

    Oleg Zhurakousky commented

    Well, back to the original question, ACK-type reply would have to be originated at the last endpoint down the pipeline and travel back to the Gateway, which means its a reply and it works today as is. There is no other way for the Gateway to know what happened down the pipe unless it receives a reply message especially in the case of async invocation.
    However, it also means that reply sent by the endpoint and reply returned by the gateway need to be "close enough" so you can configure a converter/transformer. However such transformation could be greatly simplified via SpEL on the "receive" and is consistent with what we are doing on the "send". For example, based on Dave's original XML config I can argue that 'return-value" attribute first should be renamed to "return-expression" and headers.'$timestamp' simply means extract timestamp from the already returned payload and give it back to the gateway as a returned value instead of the whole payload.

  5. spring-operator commented on Jun 28, 2010

    @spring-operator
    ContributorAuthor

    Dave Syer commented

    Actually, I don't want an ACK from the last endpoint (unless it is single threaded). I just want to know that the message arrived (that's what an ACK is) or not. I don't care what the XML attribute name is at this point (return-expression works just fine).

    An extension to this pattern is something else I struggle with a lot is polling for a reply (the real one from the final endpoint). Maybe the ACK could be in the form of a Future?

  6. spring-operator commented on Jun 28, 2010

    @spring-operator
    ContributorAuthor

    Mark Fisher commented

    This is beginning to sound like the AsyncMessageChannelTemplate (or simply adding async methods to the existing MessageChannelTemplate) that we've prototyped but have yet to officially add. The idea would be to have parallel methods, such as asyncSendAndReceive(). That would return a Future<Message<?>>. Having a @gateway or <gateway> configuration that delegates to those async methods might just be a matter of adding "async=true" and/or detecting the Future<?> or AsyncResult return type on the method.

  7. spring-operator commented on Jun 29, 2010

    @spring-operator
    ContributorAuthor

    Oleg Zhurakousky commented

    @Dave
    Actually, I don't want an ACK from the last endpoint (unless it is single threaded). I just want to know that the message arrived (that's what an ACK is) or not. - arrived where? (gateway, next endpoint, last???)

  8. spring-operator commented on Aug 31, 2010

    @spring-operator
    ContributorAuthor

    Mark Fisher commented

    We need to consider how to be more flexible about which operation is invoked on the underlying gateway (or soon to be MessagingTemplate instead).

    Currently, we have the following logic:

    1. no-arg method -> receive()
    2. void returning method with arg(s) -> send()
    3. non-void returning method with arg(s) -> sendAndReceive()

    We should be able to support more options. For example, if @Payload is present on a no-arg method, then it should be interpreted as send or sendAndReceive() depending on whether it has a non-void return value. Likewise, if a non-void return method with arg(s) has some indicator that it can return something immediately (like Dave's example), then it could be interpreted as a send() only, followed by a return of something evaluated against the Message that has just been sent (or a literal value).

  9. spring-operator commented on Sep 2, 2010

    @spring-operator
    ContributorAuthor

    Mark Fisher commented

    After some discussion, I think the most reasonable first step is to simply support methods that have a Future return type.

    This should be able to build directly on top of #5406.

  10. spring-operator commented on Sep 2, 2010

    @spring-operator
    ContributorAuthor

    Mark Fisher commented

    Actually, the Future support was added without depending on #5406. Internally, GatewayProxyFactoryBean just handles asynchronous execution when a Future return type is defined.

  11. spring-operator commented on Sep 3, 2010

    @spring-operator
    ContributorAuthor

    Mark Fisher commented

    This issue has been superseded by #5408.

    We should discuss any use-cases in light of the Future return option in order to determine if there are other changes that should be made. That feature alone seems appropriate for the Gateway interface support, however, since a Future return is the "normal" way to deal with asynchronous tasks. We do have a lot of flexibility in terms of what might be returned to the Future as well, but those would all be based on downstream processing.

    Also, the Future seems like the appropriate solution for the Gateway interface, since the purpose of "Messaging Gateway" as described in EIP is to separate application code from the messaging API. While we do support Message return types in Gateway interfaces (and now Future<Message> as well), plain "domain" objects and simple primitives/wrappers should be more common as the expected return types of those interface methods. In more sophisticated use-cases where the awareness of the messaging API is not a problem (e.g. caller continues to poll on a replyChannel that had been passed in the header, or knows about some custom "ID" header it uses to lookup the object from a downstream MessageStore), then the MessagingTemplate and the new AsyncMessagingTemplate should be able to handle any send, receive, or sendAndReceive operations (see #5406 for details about AsyncMessagingTemplate and #5357 to add comments about how we may deal with async send-only cases).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions