GH-600 Fix logic in Azure adapter to ensure proper handling of sveral functions

This also addresses re-initialization of AC when the second function is invoked
Added second function to the azure examples

Resolves #600
This commit is contained in:
Oleg Zhurakousky
2021-03-11 15:26:06 +01:00
parent 29ad49cbf6
commit e82f54d69e
6 changed files with 112 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -34,6 +34,11 @@ public class Config {
SpringApplication.run(Config.class, args);
}
@Bean
public Function<Message<String>, String> echo() {
return message -> message.getPayload();
}
@Bean
public Function<Message<String>, String> uppercase(JsonMapper mapper) {
return message -> {
@@ -46,7 +51,8 @@ public class Config {
map.forEach((k, v) -> map.put(k, v != null ? v.toUpperCase() : null));
if(context != null)
context.getLogger().info(new StringBuilder().append("Function: ").append(context.getFunctionName()).append(" is uppercasing ").append(value.toString()).toString());
context.getLogger().info(new StringBuilder().append("Function: ")
.append(context.getFunctionName()).append(" is uppercasing ").append(value.toString()).toString());
return mapper.toString(map);
} catch (Exception e) {

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2012-2020 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
*
* https://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 example;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import java.util.Optional;
import org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHandler;
/**
* @author Soby Chacko
*/
public class EchoHandler extends AzureSpringBootRequestHandler<String, String> {
@FunctionName("echo")
public String execute(@HttpTrigger(name = "req", methods = {HttpMethod.GET,
HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
ExecutionContext context) {
return handleRequest(request.getBody().get(), context);
}
}