简体   繁体   English

从 java spring boot 应用程序调用谷歌云函数

[英]calling google cloud functions from java spring boot application

I'm using google cloud functions with no problem in my mobile app using specific sdk for iOS and swift.我在我的移动应用程序中使用谷歌云功能没有问题,使用特定的 sdk for iOS 和 swift。 For integrations reason I would now need to call one of my functions from a java springboot server.出于集成原因,我现在需要从 java springboot 服务器调用我的函数之一。

I cannot find any example for that, does a specific client and example exist ?我找不到任何示例,是否存在特定的客户和示例?

I can find examples for other platform but not for java.我可以找到其他平台的示例,但不能找到 java。 Am I missing something ?我错过了什么吗? can someone move me in the right direction ?有人可以让我朝着正确的方向前进吗?

Thanks谢谢

You could simply do HTTP requests, that will trigger the cloud functions.您可以简单地执行 HTTP 请求,这将触发云功能。 Here is the documentation这是文档

GCP hasdocumentation regarding the authentication on Cloud Functions. GCP 有关于 Cloud Functions 身份验证的文档 Since you need to authenticate on a Cloud Function from a VM inside your GCP project, I recommend you to read this section .由于您需要在 GCP 项目内的 VM 上对 Cloud Function 进行身份验证,因此我建议您阅读本部分

As explained, you should get an Identity Token that can authenticate on Cloud Functions.如前所述,您应该获得可以在 Cloud Functions 上进行身份验证的身份令牌。 You can fetch the token either from gcloud or the metadata server .您可以从gcloud元数据服务器获取令牌。 After you have that in whatever format you can access it without compromising your credentials (eg environment variable, file outside the repository) just perform the HTTP request to the trigger of the function.在您以任何格式访问它之后,您就可以在不影响您的凭据(例如环境变量、存储库外的文件)的情况下访问它,只需执行对函数触发器的 HTTP 请求即可。

In the end you should have something like this:最后你应该有这样的东西:

cf_trigger = "https://<region>-<project_id>.cloudfunctions.net/<function_name>"
identity_token = "foo"

HttpRequest.newBuilder()
    .uri(URI.create(cf_trigger))
    .header("Authorization", "bearer " + identity_token)
    .build();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 java11 在谷歌云上使用 mysql 部署 Spring 启动应用程序 - Deploying a Spring boot application with mysql on google cloud with java11 从JavaScript调用Java代码(春季启动) - Calling Java code from JavaScript (Spring boot) 从谷歌云存储读取 blob object(图像)正在返回 null - spring 启动应用程序 - Reading a blob object (image) from google cloud storage is returning null in camel - spring boot application 在 Google Cloud App Engine 上构建 Spring Boot 应用程序的触发器 - Build trigger for Spring Boot application on Google Cloud App Engine 连接 Spring Boot 应用程序和 google Cloud SQL 的推荐方法是什么? - What is the recomended way to connect spring boot application and google Cloud SQL? 如何在 Google Cloud Compute Engine 中部署 Spring Boot 应用程序? - How to deploy Spring Boot application in Google Cloud Compute Engine? 谷歌云发布/订阅自动配置在 Spring Boot 应用程序中不起作用 - Google cloud pub/sub autoconfigure does not work in Spring boot application 从Google Cloud Computing实例上的Spring Boot Java App访问云数据存储时收到503 - I am receiving a 503 when accessing the cloud datastore from a spring boot java app on a google cloud compute instance 在 spring 启动 java 应用程序中调用自定义 Rest 模板 - Calling Custom Rest Template in spring boot java application Google Cloud Platform管道/容器构建器在Spring Boot Java Application中使用COPY或ADD命令构建docker映像时出现问题 - Google Cloud Platform pipeline/container builder issue building docker image using COPY or ADD command for Spring Boot Java Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM