Refactor CustomRuntimeEventLoop in AWS module to ensure it is spring aot native compatible

This commit is contained in:
Oleg Zhurakousky
2021-09-21 16:08:09 +02:00
parent 48c8a6f925
commit c8f146a98a
4 changed files with 17 additions and 36 deletions

View File

@@ -28,9 +28,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cloud.function.context.FunctionCatalog;
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
@@ -48,7 +50,7 @@ import org.springframework.web.client.RestTemplate;
* @since 3.1.1
*
*/
final class CustomRuntimeEventLoop {
public final class CustomRuntimeEventLoop implements CommandLineRunner {
private static Log logger = LogFactory.getLog(CustomRuntimeEventLoop.class);
@@ -56,11 +58,19 @@ final class CustomRuntimeEventLoop {
private static final String LAMBDA_RUNTIME_URL_TEMPLATE = "http://{0}/{1}/runtime/invocation/next";
private static final String LAMBDA_INVOCATION_URL_TEMPLATE = "http://{0}/{1}/runtime/invocation/{2}/response";
private CustomRuntimeEventLoop() {
private final ConfigurableApplicationContext applicationContext;
public CustomRuntimeEventLoop(ConfigurableApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Override
public void run(String... args) throws Exception {
CustomRuntimeEventLoop.eventLoop(this.applicationContext, args);
}
@SuppressWarnings("unchecked")
static void eventLoop(ApplicationContext context) {
private static void eventLoop(ApplicationContext context, String... args) {
logger.info("Starting spring-cloud-function CustomRuntimeEventLoop");
if (logger.isDebugEnabled()) {
logger.debug("AWS LAMBDA ENVIRONMENT: " + System.getenv());

View File

@@ -44,7 +44,7 @@ public class CustomRuntimeInitializer implements ApplicationContextInitializer<G
if (!this.isWebExportEnabled(context) && isCustomRuntime()) {
if (context.getBeanFactory().getBeanNamesForType(CustomRuntimeEventLoop.class, false, false).length == 0) {
context.registerBean(StringUtils.uncapitalize(CustomRuntimeEventLoop.class.getSimpleName()),
CommandLineRunner.class, () -> args -> CustomRuntimeEventLoop.eventLoop(context));
CommandLineRunner.class, () -> new CustomRuntimeEventLoop(context));
}
}
else if (ContextFunctionCatalogInitializer.enabled

View File

@@ -1,5 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.function.adapter.aws.CustomRuntimeEventLoop
org.springframework.context.ApplicationContextInitializer=\
org.springframework.cloud.function.adapter.aws.CustomRuntimeInitializer
org.springframework.boot.env.EnvironmentPostProcessor=\