Hi, i am using version nestjs-google-pubsub=0.1.2, its working as expected, but after a few days the subscription is not getting any messages, looks like is freezing, but publishing messages in same topic works, after a while getting like 1 or 2 messages and again freezing and can not understand what is going wrong.
as well i need to publish messages in same topic as my subscriptio from above, for this i did a separate code for it, just pasting here because may be from second code is causing issue to listenng for messages
pub.sub.service.ts
import {Logger} from '@nestjs/common'
import { PubSub } from '@google-cloud/pubsub';
import {PubSubGoogleCredentials} from '../common/interfaces';
import {ConfigService} from '../config/config.service';
import {buildTopic} from '../common/helpers/tests/build-topic';
const {ENV_NAME, GOOGLE_APPLICATION_CREDENTIALS} = ConfigService.createFromDotEnvOrProcessEnv().env
const rawGoogleCredentials = Buffer.from(GOOGLE_APPLICATION_CREDENTIALS, 'base64')
const googleCredentials: PubSubGoogleCredentials = JSON.parse(rawGoogleCredentials.toString('utf-8'))
export class PubSubService {
constructor(
private readonly pubSubClient = new PubSub({
projectId: googleCredentials.project_id,
credentials: {
client_email: googleCredentials.client_email,
private_key: googleCredentials.private_key
}
}),
) {}
public async publishMessage(data: object, topic: string): Promise<void> {
const dataBuffer = Buffer.from(JSON.stringify(data));
const topicName = buildTopic(ENV_NAME, topic)
const date = new Date()
try {
const messageId = await this.pubSubClient.topic(topicName).publish(dataBuffer);
Logger.log({
status: 'ok',
description: 'Message published',
messageId,
data,
date
});
} catch (error) {
Logger.log(`Received error while publishing: ${error.message}`);
Logger.log({
status: 'error',
error: error.message,
data,
date
});
process.exitCode = 1;
}
}
}
pub.sub.module.ts
import {Module} from '@nestjs/common'
import {ConfigModule} from '../config/config.module'
import {PubSubService} from './pub.sub.service';
@Module({
imports: [
ConfigModule,
],
controllers: [],
providers: [PubSubService],
exports: [PubSubService],
})
export class PubSubModule {}
some more information
when my subscription stops receiving messages, if i try to publish a message is working pub sub, only listening messages after a day something like this stops receiving messages, messages are in the subscription but not getting any messages.
Hi, i am using version nestjs-google-pubsub=0.1.2, its working as expected, but after a few days the subscription is not getting any messages, looks like is freezing, but publishing messages in same topic works, after a while getting like 1 or 2 messages and again freezing and can not understand what is going wrong.
Could you help to find out the problem.
here is the microservice creation
here is my function for listening the subscription
Could u point me what is wrong with my code?
as well here are the list of my packages for my app
as well i need to publish messages in same topic as my subscriptio from above, for this i did a separate code for it, just pasting here because may be from second code is causing issue to listenng for messages
pub.sub.service.ts
pub.sub.module.ts
app.module.ts
some more information when my subscription stops receiving messages, if i try to publish a message is working pub sub, only listening messages after a day something like this stops receiving messages, messages are in the subscription but not getting any messages.
Thanks a lot in advance for any help