{"id":28003180,"url":"https://github.com/fnproject/fn-spring-cloud-function-example","last_synced_at":"2025-05-09T01:59:31.484Z","repository":{"id":32440577,"uuid":"112629016","full_name":"fnproject/fn-spring-cloud-function-example","owner":"fnproject","description":"Example project showing Spring Cloud Function support on Fn Project","archived":false,"fork":false,"pushed_at":"2022-04-22T10:51:54.000Z","size":7,"stargazers_count":2,"open_issues_count":4,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-09T01:59:26.350Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnproject.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-30T15:41:09.000Z","updated_at":"2022-04-22T10:51:39.000Z","dependencies_parsed_at":"2022-07-22T08:22:05.307Z","dependency_job_id":null,"html_url":"https://github.com/fnproject/fn-spring-cloud-function-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnproject%2Ffn-spring-cloud-function-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnproject%2Ffn-spring-cloud-function-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnproject%2Ffn-spring-cloud-function-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnproject%2Ffn-spring-cloud-function-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnproject","download_url":"https://codeload.github.com/fnproject/fn-spring-cloud-function-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176436,"owners_count":21866142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-09T01:59:31.055Z","updated_at":"2025-05-09T01:59:31.473Z","avatar_url":"https://github.com/fnproject.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example Spring Cloud Function\n\nThis is an example [spring cloud function](https://github.com/spring-cloud/spring-cloud-function) \nproject running on Fn using the \n[`SpringCloudFunctionInvoker`](/runtime/src/main/java/com/fnproject/fn/runtime/spring/SpringCloudFunctionInvoker.java).\n\nFirstly, if you have used `fn` before you'll want to make sure you have the latest runtime image which includes the Spring support:\n\n```bash\n$ docker pull fnproject/fdk-java:latest\n```\n\nThen you can build and deploy the app\n\nOnce the app is deployed you need to make the route through API Gateway\nhttps://docs.oracle.com/en-us/iaas/developer-tutorials/tutorials/functions/func-api-gtw/01-summary.htm\n\n\n```bash\nfn build\nfn deploy --app \u003capp_name\u003e\n```\n\nTry invoking the image through command \n```bash\nfn invoke \u003capp_name\u003e \u003cfunction_name\u003e\n```\nDouble-check that the VCN includes an internet gateway or service gateway. \nFor Oracle Functions to be able to access Oracle Cloud Infrastructure Registry to pull an image, \nthe VCN must include an internet gateway or a service gateway. Follow the link\nhttps://docs.oracle.com/en-us/iaas/Content/Functions/Tasks/functionstroubleshooting_topic-Issues-invoking-functions.htm\n\nUnder the policy, check  for the policy for allowing all the compartment user to have access over the url\n```bash\nALLOW any-user to use functions-family in \u003ccompartment\u003e where ALL {request.principal.type= 'ApiGateway', request.resource.compartment.id = '\u003ccompartment_id\u003e'}\n```\n\nNow you can call those functions using `fn invoke` or curl:\n\n```bash\n$ echo \"Hi there\" | fn invoke spring-cloud-fn \nHello world\n\n$ curl -d \"Bob\" http://\u003curl-apigateway\u003e/hello\nHello Bob\n```\n\n\n## Code walkthrough\n\n```java\n@Configuration\n```\nDefines that the class is a \n[Spring configuration class](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html) \nwith `@Bean` definitions inside of it.\n\n```java\n@Import(ContextFunctionCatalogAutoConfiguration.class)\n```\nSpecifies that this configuration uses a [`InMemoryFunctionCatalog`](https://github.com/spring-cloud/spring-cloud-function/blob/a973b678f1d4d6f703a530e2d9e071b6d650567f/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/InMemoryFunctionCatalog.java)\nthat provides the beans necessary\nfor the `SpringCloudFunctionInvoker`.\n\n```java\n    ...\n    @FnConfiguration\n    public static void configure(RuntimeContext ctx) {\n        ctx.setInvoker(new SpringCloudFunctionInvoker(SCFExample.class));\n    }\n```\n\nSets up the Fn Java FDK to use the SpringCloudFunctionInvoker which performs function discovery and invocation.\n\n```java\n    // Unused - see https://github.com/fnproject/fdk-java/issues/113\n    public void handleRequest() { }\n```\n\nCurrently the runtime expects a method to invoke, however this isn't used in the SpringCloudFunctionInvoker so we declare an empty method simply to keep the runtime happy. This will not be necessary for long - see the linked issue on GitHub.\n\n\n```java\n    @Bean\n    public Function\u003cString, String\u003e function(){\n        return value -\u003e \"Hello, \" + ((value == null || value.isEmpty()) ? \"world\"  : value ) + \"!\";\n        }\n```\n\nFinally the heart of the configuration; the bean definitions of the functions to invoke.\n\nNote that these methods are not the functions themselves. They are factory methods which *return* the functions. As the Beans are constructed by Spring it is possible to use `@Autowired` dependency injection.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnproject%2Ffn-spring-cloud-function-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnproject%2Ffn-spring-cloud-function-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnproject%2Ffn-spring-cloud-function-example/lists"}