英文:
Google Cloud Pub Sub still sending notifications even after stopping all events for the user
问题
在我的节点服务器中,我正在获取用户的Gmail收件箱权限,并使用Google Cloud的Pub/Sub向它们添加监视器。
以下是代码部分:
async addWatcherToGmailInbox({
gmailInboxRefreshToken,
}: {
gmailInboxRefreshToken: string;
}): Promise<boolean> {
const auth = await this.loadAuth(gmailInboxRefreshToken);
const gmail = google.gmail({
version: 'v1',
auth,
});
await gmail.users.watch({
userId: 'me',
requestBody: {
labelIds: ['INBOX'],
topicName: 'projects/<project-name>/topics/<topic-name>',
},
});
return true;
}
但是当用户从我的平台取消链接他的Gmail帐户时,我首先停止通知,然后撤销令牌。但不知何故,在我的Pub/Sub订阅者的"on"事件中仍然收到通知。
停止通知的代码:
async removeWatcherFromGmailInbox({
gmailInboxRefreshToken,
}: {
gmailInboxRefreshToken: string;
}): Promise<boolean> {
const auth = await this.loadAuth(gmailInboxRefreshToken);
const gmail = google.gmail({
version: 'v1',
auth,
});
gmail.users.stop({
userId: 'me',
});
return true;
}
我Pub/Sub订阅者事件中获取通知的部分:
const pubsub = new PubSub({
projectId: <project-name>,
});
this.logger.log('Google Pubsub initialized, fetching topics...');
const subs = await pubsub.getSubscriptions();
const sub = subs[0][0];
// Receive callbacks for new messages on the subscription
sub.on('message', (message) => {
this.logger.log('Received message:', message.data.toString());
const data = JSON.parse(message.data.toString());
});
// Receive callbacks for errors on the subscription
sub.on('error', (error) => {
this.logger.error('Received error:', error);
});
当用户希望撤销令牌时,我漏掉了什么来停止通知?
注意:我确实记录了停止函数的响应。它返回一个空的正文,就像在文档中提到的那样。
英文:
In my node server, I am taking user's gmail inbox permissions and adding a watcher to all of them using google cloud's pub sub.
Here's the code:
async addWatcherToGmailInbox({
gmailInboxRefreshToken,
}: {
gmailInboxRefreshToken: string;
}): Promise<boolean> {
const auth = await this.loadAuth(gmailInboxRefreshToken);
const gmail = google.gmail({
version: 'v1',
auth,
});
await gmail.users.watch({
userId: 'me',
requestBody: {
labelIds: ['INBOX'],
topicName: 'projects/<project-name>/topics/<topic-name>',
},
});
return true;
}
But when user unlinks his gmail account from my platform, I stop the notifications first and then revoke the token. But somehow, I still get notifications in my pub sub subscriber on
event.
Stopping notifications code:
async removeWatcherFromGmailInbox({
gmailInboxRefreshToken,
}: {
gmailInboxRefreshToken: string;
}): Promise<boolean> {
const auth = await this.loadAuth(gmailInboxRefreshToken);
const gmail = google.gmail({
version: 'v1',
auth,
});
gmail.users.stop({
userId: 'me',
});
return true;
}
My pub sub subscriber event where I'm getting notifications:
const pubsub = new PubSub({
projectId: <project-name>,
});
this.logger.log('Google Pubsub initialized, fetching topics...');
const subs = await pubsub.getSubscriptions();
const sub = subs[0][0];
// Receive callbacks for new messages on the subscription
sub.on('message', (message) => {
this.logger.log('Received message:', message.data.toString());
const data = JSON.parse(message.data.toString());
});
// Receive callbacks for errors on the subscription
sub.on('error', (error) => {
this.logger.error('Received error:', error);
});
What am I missing to stop notifications for a user when he/she wants to revoke the token.
Note: I did log the response of stop function. It returns empty body just like it's mentioned in the docs.
答案1
得分: 1
你可以停止发布主题中的消息,但订阅中仍然存在消息,PubSub会尝试将它们传递直到确认或消息过期。您还可以清除订阅。
英文:
You can stop to publish message in topic, but there is still messages in the subscription and PubSub try to deliver them until ack or message expiration. You can also purge the subscription
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论