Edit Javadoc in MessageRoutingFunction and RoutingFunction
Refine implementation of RoutingFunction Closes #1216
This commit is contained in:
committed by
Oleg Zhurakousky
parent
06179919b3
commit
536b49775e
@@ -21,21 +21,22 @@ import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* Java-based strategy to assist with determining the name of the route-to function definition.
|
||||
* Once implementation is registered as a bean in application context
|
||||
* Once an implementation is registered as a bean in application context
|
||||
* it will be picked up by the {@link RoutingFunction}.
|
||||
*
|
||||
* <p/>
|
||||
* While {@link RoutingFunction} provides several mechanisms to determine the route-to function definition
|
||||
* this callback takes precedence over all of them.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author John Blum
|
||||
* @since 3.1
|
||||
*/
|
||||
public interface MessageRoutingCallback {
|
||||
|
||||
/**
|
||||
* Computes and returns the instance of {@link String} which encapsulates,
|
||||
* at the very minimum, function definition.
|
||||
* <br><br>
|
||||
* Computes and returns an instance of {@link String}, which encapsulates,
|
||||
* at the very minimum, a function definition.
|
||||
* <p/>
|
||||
* Providing such message is primarily an optimization feature. It could be useful for cases
|
||||
* where routing procedure is complex and results in, let's say, conversion of the payload to
|
||||
* the target type, which would effectively be thrown away if the ability to modify the target
|
||||
|
||||
@@ -45,10 +45,11 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* An implementation of Function which acts as a gateway/router by actually
|
||||
* An implementation of {@link Function} which acts as a gateway/router by actually
|
||||
* delegating incoming invocation to a function specified .. .
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @author John Blum
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
@@ -127,8 +128,7 @@ public class RoutingFunction implements Function<Object, Object> {
|
||||
private Object route(Object input, boolean originalInputIsPublisher) {
|
||||
FunctionInvocationWrapper function = null;
|
||||
|
||||
if (input instanceof Message) {
|
||||
Message<?> message = (Message<?>) input;
|
||||
if (input instanceof Message<?> message) {
|
||||
if (this.routingCallback != null) {
|
||||
String functionDefinition = this.routingCallback.routingResult(message);
|
||||
if (StringUtils.hasText(functionDefinition)) {
|
||||
@@ -155,7 +155,7 @@ public class RoutingFunction implements Function<Object, Object> {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (input instanceof Publisher) {
|
||||
else if (input instanceof Publisher<?> publisher) {
|
||||
if (StringUtils.hasText(functionProperties.getDefinition())) {
|
||||
function = functionFromDefinition(functionProperties.getDefinition());
|
||||
}
|
||||
@@ -163,9 +163,9 @@ public class RoutingFunction implements Function<Object, Object> {
|
||||
function = this.functionFromExpression(functionProperties.getRoutingExpression(), input);
|
||||
}
|
||||
else {
|
||||
return input instanceof Mono
|
||||
? Mono.from((Publisher<?>) input).map(v -> route(v, originalInputIsPublisher))
|
||||
: Flux.from((Publisher<?>) input).map(v -> route(v, originalInputIsPublisher));
|
||||
return input instanceof Mono<?> mono
|
||||
? Mono.from(mono).map(v -> route(v, originalInputIsPublisher))
|
||||
: Flux.from(publisher).map(v -> route(v, originalInputIsPublisher));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -184,7 +184,7 @@ public class RoutingFunction implements Function<Object, Object> {
|
||||
}
|
||||
}
|
||||
|
||||
if (function.getTarget().equals(this)) {
|
||||
if (this.equals(function.getTarget())) {
|
||||
throw new IllegalStateException("Failed to establish route, and routing to itself is not allowed as it creates a loop. Please provide: "
|
||||
+ "'spring.cloud.function.definition' as Message header or as application property or "
|
||||
+ "'spring.cloud.function.routing-expression' as application property.");
|
||||
|
||||
Reference in New Issue
Block a user