Skip to content

Commit 148d23e

Browse files
committed
GH-1248 Add support for passing host/port to Grps MessageRoutingCallback
Resolves #1248
1 parent 7e933b7 commit 148d23e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

spring-cloud-function-adapters/spring-cloud-function-grpc/src/main/java/org/springframework/cloud/function/grpc/GrpcFunctionAutoConfiguration.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,23 @@ public class GrpcFunctionAutoConfiguration {
3737
public static String GRPC_INVOKER_FUNCTION = "grpcInvokerFunction";
3838

3939
public static String GRPC = "grpc";
40+
41+
public static String GRPC_HOST = "grpcHost";
42+
43+
public static String GRPC_PORT = "grpcPort";
4044

4145
@Bean
4246
public Function<Message<byte[]>, Message<?>> grpcInvokerFunction() {
43-
return input -> {
44-
return GrpcUtils.requestReply(input);
47+
return message -> {
48+
if (message.getHeaders().containsKey(GRPC_HOST)) {
49+
String host = (String) message.getHeaders().get(GRPC_HOST);
50+
int port = message.getHeaders().get(GRPC_PORT) instanceof String stringPort
51+
? Integer.parseInt(stringPort)
52+
: (int)message.getHeaders().get(GRPC_PORT);
53+
54+
return GrpcUtils.requestReply(host, port, message);
55+
}
56+
return GrpcUtils.requestReply(message);
4557
};
4658
}
4759

0 commit comments

Comments
 (0)