Google 云存储功能在订阅者连接时发送已发送的消息
Google cloud storage function sending already delivered message when subscriber connects
我在 google 存储云中有一个存储桶。此外,我有一个存储功能,每当在此存储桶上创建新的 file/folder 时都会触发该功能。此功能的想法是在 google PubSub 上发布在 "monitoring" 文件夹下创建的文件。因此,一旦有新文件,它就会被触发,但如果文件是在上述文件夹下创建的,则只会将消息发送到 PubSub。此外,我有一个 Java 应用程序订阅了接收此消息的 PubSub。它能够毫无问题地接收消息,但是当我关闭应用程序并再次午餐时,几分钟后,之前传递的消息又回来了。我查看了日志,是否触发了存储功能,但没有,而且似乎没有再次向 PubSub 发送消息。所有消息均已确认,PubSub 为空。我是否缺少与存储功能或 PubSub 相关的内容?
这是我的存储函数定义:
const {PubSub} = require('@google-cloud/pubsub');
const topicName = 'test-topic-1';
const monitoringFolder = 'monitoring/';
exports.handler = (event, context) => {
console.log(event);
if (isMonitoringFolder(event.name)) {
publishEvent(event);
}
};
const publishEvent = (event) => {
const pubSub = new PubSub();
const payload = {
bucket: event.bucket,
filePath: event.name,
timeCreated: event.timeCreated
};
const data = Buffer.from(JSON.stringify(payload));
pubSub
.topic(topicName)
.publish(data)
.then(id => console.log(`${payload.filePath} was added to pubSub with id: ${id}`))
.catch(err => console.log(err));
};
const isMonitoringFolder = filePath => filePath.search(monitoringFolder) != -1
非常感谢任何建议
Pubsub 不保证消息会出现一次
Google Cloud Pubsub 有至少一次交付政策。这会为每个订阅至少传递一次已发布的消息。但是可以多次送达
我在 google 存储云中有一个存储桶。此外,我有一个存储功能,每当在此存储桶上创建新的 file/folder 时都会触发该功能。此功能的想法是在 google PubSub 上发布在 "monitoring" 文件夹下创建的文件。因此,一旦有新文件,它就会被触发,但如果文件是在上述文件夹下创建的,则只会将消息发送到 PubSub。此外,我有一个 Java 应用程序订阅了接收此消息的 PubSub。它能够毫无问题地接收消息,但是当我关闭应用程序并再次午餐时,几分钟后,之前传递的消息又回来了。我查看了日志,是否触发了存储功能,但没有,而且似乎没有再次向 PubSub 发送消息。所有消息均已确认,PubSub 为空。我是否缺少与存储功能或 PubSub 相关的内容?
这是我的存储函数定义:
const {PubSub} = require('@google-cloud/pubsub');
const topicName = 'test-topic-1';
const monitoringFolder = 'monitoring/';
exports.handler = (event, context) => {
console.log(event);
if (isMonitoringFolder(event.name)) {
publishEvent(event);
}
};
const publishEvent = (event) => {
const pubSub = new PubSub();
const payload = {
bucket: event.bucket,
filePath: event.name,
timeCreated: event.timeCreated
};
const data = Buffer.from(JSON.stringify(payload));
pubSub
.topic(topicName)
.publish(data)
.then(id => console.log(`${payload.filePath} was added to pubSub with id: ${id}`))
.catch(err => console.log(err));
};
const isMonitoringFolder = filePath => filePath.search(monitoringFolder) != -1
非常感谢任何建议
Pubsub 不保证消息会出现一次
Google Cloud Pubsub 有至少一次交付政策。这会为每个订阅至少传递一次已发布的消息。但是可以多次送达