Add new feature to initialize a Supplier from a remote HTTP endpoint

Kind of like the SupplierExporter but to create the Supplier itself.
With this in place you can define the templateUrl (destination) and
the originaUrl (source) and use the app as a pipeline for events
from/to HTTP.

Provide functional bean support for HTTP export

Add autoconfig to AWS adapter for custom runtime

Fix HttpSupplier to always supply Message if headers are included

Fix registration of origin supplier in functional beans

Add docs on new AWS features

Add custom runtime sample
This commit is contained in:
Dave Syer
2019-02-13 06:26:12 -06:00
committed by Oleg Zhurakousky
parent cdca44f714
commit 428243ce48
26 changed files with 1239 additions and 42 deletions

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.adapter.aws;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.function.web.source.DestinationResolver;
import org.springframework.cloud.function.web.source.FunctionExporterAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author Dave Syer
*/
@Configuration
@AutoConfigureBefore(FunctionExporterAutoConfiguration.class)
public class CustomRuntimeAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public DestinationResolver destinationResolver() {
return new LambdaDestinationResolver();
}
@Bean
public CommandLineRunner backgrounder() {
return args -> background();
}
static void background() {
Thread thread = new Thread(() -> {
System.out.println("Started");
while (true) {
try {
Thread.sleep(500L);
}
catch (InterruptedException e) {
}
}
});
thread.setDaemon(false);
thread.start();
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.adapter.aws;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cloud.function.context.config.ContextFunctionCatalogInitializer;
import org.springframework.cloud.function.web.source.DestinationResolver;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.annotation.Order;
/**
* @author Dave Syer
*/
@Order(0)
public class CustomRuntimeInitializer
implements ApplicationContextInitializer<GenericApplicationContext> {
@Override
public void initialize(GenericApplicationContext context) {
if (ContextFunctionCatalogInitializer.enabled && context.getEnvironment()
.getProperty("spring.functional.enabled", Boolean.class, false)) {
if (context.getBeanFactory().getBeanNamesForType(DestinationResolver.class,
false, false).length == 0) {
context.registerBean(LambdaDestinationResolver.class,
() -> new LambdaDestinationResolver());
}
context.registerBean(CommandLineRunner.class,
() -> args -> CustomRuntimeAutoConfiguration.background());
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2018-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.adapter.aws;
import java.util.function.Supplier;
import org.springframework.cloud.function.web.source.DestinationResolver;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
public class LambdaDestinationResolver implements DestinationResolver {
@Override
public String destination(Supplier<?> supplier, String name, Object value) {
Message<?> message = (Message<?>) value;
MessageHeaders headers = message.getHeaders();
if (headers.containsKey("lambda-runtime-aws-request-id")) {
return (String) headers.get("lambda-runtime-aws-request-id");
}
return "unknown";
}
}

View File

@@ -0,0 +1,4 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.function.adapter.aws.CustomRuntimeAutoConfiguration
org.springframework.context.ApplicationContextInitializer=\
org.springframework.cloud.function.adapter.aws.CustomRuntimeInitializer