0

The spring-cloud-function-deployer examples all show the deployed function being loaded on startup i.e. the ApplicationContext is started with the necessary properties, pointing at the packaged jar to load.

Is there a way to call the deployer programatically at runtime, instead of relying on the auto-configuration? In case I want to deploy the function sometime after the application context has started, or if I want to deploy multiple functions from the same jar etc.

Also is there a way to undeploy any loaded functions, or is this simple as removing the function from the catalog?

Cœur
  • 37,241
  • 25
  • 195
  • 267
James
  • 1,237
  • 4
  • 22
  • 43

1 Answers1

2

as stated in the GH response, you absolutely can deploy functions at runtime.

String[] args = new String[] {
                "--spring.cloud.function.location=target/it/bootapp/target/bootapp-1.0.0.RELEASE-exec.jar",
                "--spring.cloud.function.definition=uppercase" };

ApplicationContext context = SpringApplication.run(DeployerApplication.class, args);
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
Function<String, String> function = catalog.lookup("uppercase");
// use the function

You can see sample deployments here and the corresponding test.

Oleg Zhurakousky
  • 5,820
  • 16
  • 17
  • Does that not mean you will have to run a separate ApplicationContext for every function you want to load programatically? – James Jan 29 '20 at 14:55
  • Yes, but why would it matter? The context contains all other supporting beans required to "deploy" function. – Oleg Zhurakousky Jan 29 '20 at 14:57
  • Was just thinking in terms of latency between deploying a function and being able to invoke it, loading an entirely new context is quite slow. Also it would make sharing connection pools etc. For any upstream adapters for the function difficult, although I guess there's arguments around isolation that could say that's a good thing. – James Jan 29 '20 at 18:30