You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow Gateway to return information about the message status [INT-943] #4959
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.:
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.
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).
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.
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.
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?
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.
@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???)
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:
no-arg method -> receive()
void returning method with arg(s) -> send()
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).
Actually, the Future support was added without depending on #5406. Internally, GatewayProxyFactoryBean just handles asynchronous execution when a Future return type is defined.
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).
Activity
spring-operator commentedon Dec 23, 2009
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?
spring-operator commentedon May 6, 2010
Mark Fisher commented
We should consider this refactoring after the changes described here:
http://jira.springframework.org/browse/INT-1129
spring-operator commentedon Jun 24, 2010
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.
spring-operator commentedon Jun 28, 2010
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.
spring-operator commentedon Jun 28, 2010
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?
spring-operator commentedon Jun 28, 2010
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.
spring-operator commentedon Jun 29, 2010
Oleg Zhurakousky commented
@DaveActually, 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???)
spring-operator commentedon Aug 31, 2010
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:
We should be able to support more options. For example, if
@Payloadis 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).spring-operator commentedon Sep 2, 2010
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.
spring-operator commentedon Sep 2, 2010
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.
spring-operator commentedon Sep 3, 2010
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).