java - 如何将 blob 文件发布到 GCP Pub/Sub?
问题描述
目前,我正在使用 java 将消息和数据发布到 pub/sub。我想知道如何将 blob 文件发布到发布/订阅服务?
@PostMapping(value = "/publish")
public String publishMessage(@RequestBody MyAppGCPMessage message) {
var attributes = singleFormatAttributes(message);
var messagePub = PubsubMessage.newBuilder().putAllAttributes(attributes).build();
repository.publish(messagePub);
return "message published to google Pub/Sub successfully";
}
private Map<String, String> singleFormatAttributes(MyAppGCPMessage entity) {
return Map.of(
"id", entity.getId(),
"name", entity.getName(),
"email",entity.getEmailId()
);
}
解决方案
您不能将 blob 文件发布到 pub/sub。您可以做的是将文件上传到云存储并设置通知到您选择的发布/订阅主题。设置一个云函数以响应事件而被触发。您将在事件数据中获得上传文件的位置。在 Cloud Function 中执行您想要执行的任何处理。
推荐阅读
- javascript - 从 JSON 中的对象获取项目
- java - IntStream 如何避免隐藏的装箱成本
- node.js - 无法使用 config.get() 读取节点中的自定义环境变量
- python - 如何从叶地图中提取已经存在的地理标签?
- javascript - eslint 为什么我的插件显示未找到规则定义?
- python - xarray n00b 问题:它可以处理不规则大小的矩阵吗?
- java - java中的逗号吐/分隔jsonnode
- php - 使用 PHP 提取上下文中单词出现的实例,并按特定条件过滤结果
- django - 如果我删除迁移文件,会有问题吗?
- google-apps-script - 如何在谷歌脚本中使用 setValues