我应该在运行时创建消息通道吗?
Should I create message channel at runtime?
使用MQ
系统时,如RabbitMQ
、Google Pub/Sub
。
我应该在应用程序运行时创建消息 channel/queue 吗?或者,先手动创建它?
例如,当使用 Google Pub/Sub
时,在运行时创建 topic
。
async function createTopic(topicName: string): Promise<any> {
const topicInstance = pubsubClient.topic(topicName);
const [exists] = await topicInstance.exists();
if (exists) {
logger.info(`${topicName} topic is existed`);
return;
}
return pubsubClient
.createTopic(topicName)
.then((data) => {
logger.info(`Create topic ${topicName} successfully`);
return data;
})
.catch((err) => logger.error(err));
}
特别是考虑开发、部署和持续集成过程。
看过一本书说实时创建消息队列用处不大
没有什么可以阻止您在运行时创建主题。但是,除非您的客户正在检查主题是否存在并等待订阅它,否则您将发布永远不会收到的消息。更好的模式是预先建立您的主题,自动缩放订阅者(可能 运行 在云函数中)准备好接收消息并在您的发布者开始生成它们时采取适当的行动。
使用MQ
系统时,如RabbitMQ
、Google Pub/Sub
。
我应该在应用程序运行时创建消息 channel/queue 吗?或者,先手动创建它?
例如,当使用 Google Pub/Sub
时,在运行时创建 topic
。
async function createTopic(topicName: string): Promise<any> {
const topicInstance = pubsubClient.topic(topicName);
const [exists] = await topicInstance.exists();
if (exists) {
logger.info(`${topicName} topic is existed`);
return;
}
return pubsubClient
.createTopic(topicName)
.then((data) => {
logger.info(`Create topic ${topicName} successfully`);
return data;
})
.catch((err) => logger.error(err));
}
特别是考虑开发、部署和持续集成过程。
看过一本书说实时创建消息队列用处不大
没有什么可以阻止您在运行时创建主题。但是,除非您的客户正在检查主题是否存在并等待订阅它,否则您将发布永远不会收到的消息。更好的模式是预先建立您的主题,自动缩放订阅者(可能 运行 在云函数中)准备好接收消息并在您的发布者开始生成它们时采取适当的行动。