Make Azure function initializer a bit more flexible
This commit is contained in:
@@ -21,6 +21,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.microsoft.azure.functions.ExecutionContext;
|
||||
import com.microsoft.azure.functions.OutputBinding;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
@@ -50,6 +51,17 @@ public class AzureSpringBootRequestHandler<I, O> extends AzureSpringFunctionInit
|
||||
return result(convertedEvent, output);
|
||||
}
|
||||
|
||||
public void handleOutput(I foo, OutputBinding<O> bar, ExecutionContext context) {
|
||||
if (context != null) {
|
||||
context.getLogger().fine("Handler trigger processed a request.");
|
||||
}
|
||||
initialize(context);
|
||||
|
||||
Object convertedEvent = convertEvent(foo);
|
||||
Publisher<?> output = apply(extract(convertedEvent));
|
||||
bar.setValue(result(convertedEvent, output));
|
||||
}
|
||||
|
||||
protected Object convertEvent(I input) {
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -53,10 +53,11 @@ public class AzureSpringFunctionInitializer implements Closeable {
|
||||
@Autowired(required = false)
|
||||
private FunctionCatalog catalog;
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
private volatile static ConfigurableApplicationContext context;
|
||||
|
||||
public AzureSpringFunctionInitializer(Class<?> configurationClass) {
|
||||
this.configurationClass = configurationClass;
|
||||
this.configurationClass = configurationClass == null ? getClass()
|
||||
: configurationClass;
|
||||
}
|
||||
|
||||
public AzureSpringFunctionInitializer() {
|
||||
@@ -108,8 +109,13 @@ public class AzureSpringFunctionInitializer implements Closeable {
|
||||
}
|
||||
else {
|
||||
Set<String> functionNames = this.catalog.getNames(Function.class);
|
||||
this.function = this.catalog.lookup(Function.class,
|
||||
functionNames.iterator().next());
|
||||
if (functionNames.size() == 1) {
|
||||
this.function = this.catalog.lookup(Function.class,
|
||||
functionNames.iterator().next());
|
||||
}
|
||||
else {
|
||||
this.function = this.catalog.lookup(Function.class, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user