Streamline and refactor the azure and the azure-web adapters.

- Add SCF/Azure Gradle sample and docs.
- Move the function-azure-di-samples into standalone projects.
 - Apply the name convetion and project structure for the SCF adaptes.
   E.g.  function-sample-azure-XXX projects under the spring-cloud-function-samples root.
 - Remove the redudant samples.
 - Improve the samples docs and the Adapter generic docs.
- Streamline docs.
- Add azure web adapter sample and README.
- Add Spring Azure Functions banner for azure and azure web adapters.
- azure-web adapter fixes:
  - Fix issues in serverles-web ProxyHttpServletResponse implementation.
  - Remove the custom FunctionClassUtils utils in favor of scf-context/util/FunctionClassUtils.
- Remove redundant files.
- Add FunctionInvoker deprecation annotations.
- Extend the time trigger sample with Retry policies example.
This commit is contained in:
Christian Tzolov
2023-07-14 18:46:42 +02:00
parent 64f57bcef8
commit 6299a5366b
88 changed files with 1834 additions and 1312 deletions

View File

@@ -0,0 +1,55 @@
/*
* Copyright 2021-2022 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 com.example.azure.di.timetriggerdemo;
import java.util.function.Consumer;
import com.microsoft.azure.functions.ExecutionContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
@SpringBootApplication
public class TimeTriggerDemoApplication {
private static Log logger = LogFactory.getLog(TimeTriggerDemoApplication.class);
public static void main(String[] args) {
SpringApplication.run(TimeTriggerDemoApplication.class, args);
}
@Bean
public Consumer<Message<String>> uppercase() {
return message -> {
String timeInfo = message.getPayload();
String value = timeInfo.toUpperCase();
logger.info("Timer is triggered with TimeInfo: " + value);
// (Optionally) access and use the Azure function context.
ExecutionContext context = (ExecutionContext) message.getHeaders().get(UppercaseHandler.EXECUTION_CONTEXT);
context.getLogger().info("Execution Context Log - TimeInfo: " + value);
// No response.
};
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2021-2022 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 com.example.azure.di.timetriggerdemo;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.annotation.ExponentialBackoffRetry;
import com.microsoft.azure.functions.annotation.FixedDelayRetry;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.TimerTrigger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
@Component
public class UppercaseHandler {
public static String EXECUTION_CONTEXT = "executionContext";
private static AtomicInteger count = new AtomicInteger();
@Autowired
private Consumer<Message<String>> uppercase;
@FunctionName("uppercase")
@FixedDelayRetry(maxRetryCount = 4, delayInterval = "00:00:10")
public void execute(@TimerTrigger(name = "keepAliveTrigger", schedule = "0 */1 * * * *") String timerInfo,
ExecutionContext context) {
Message<String> message = MessageBuilder
.withPayload(timerInfo)
.setHeader(EXECUTION_CONTEXT, context)
.build();
this.uppercase.accept(message);
}
@FunctionName("uppercaseExpRetry")
@ExponentialBackoffRetry(maxRetryCount = 4, maximumInterval = "00:15:00", minimumInterval = "00:00:03")
public void executeExpRetry(@TimerTrigger(name = "keepAliveTrigger", schedule = "*/10 * * * * *") String timerInfo,
ExecutionContext context) {
if (count.incrementAndGet() < 3) {
context.getLogger().info("EMULATE ERROR# " + count.get());
throw new IllegalStateException("Emulated ERROR# " + count.get());
}
context.getLogger().info("ERRORLESS EXECUTION");
Message<String> message = MessageBuilder
.withPayload(timerInfo)
.setHeader(EXECUTION_CONTEXT, context)
.build();
this.uppercase.accept(message);
}
}

View File

@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
}
}

View File

@@ -0,0 +1,8 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "",
"FUNCTIONS_WORKER_RUNTIME": "java"
}
}

View File

@@ -0,0 +1,13 @@
package com.example.azure.di.timetriggerdemo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class TimetriggerDemoApplicationTests {
@Test
void contextLoads() {
}
}