Closed RezaRahmati closed 2 years ago
Hi, could you provide pubsub message example which client sends?
@p-fedyukovich Sure
message example
{
"broker": "Smart Prime Group Ltd.",
"time": "2022-02-14T00:21:01.137Z",
"symbol": "SPA35",
"ask": 50.25,
"bid": 60.50,
"volume": 6500,
"publisherTime": "2022-02-14T00:21:01.137Z"
}
here is my topic schema
{
"type": "record",
"name": "Avro",
"fields": [
{
"name": "broker",
"type": "string"
},
{
"name": "time",
"type": "string"
},
{
"name": "symbol",
"type": "string"
},
{
"name": "ask",
"type": "double"
},
{
"name": "bid",
"type": "double"
},
{
"name": "volume",
"type": "double"
},
{
"name": "publisherTime",
"type": "string"
}
]
}
p.s I tried with this lib and it's working fine https://github.com/crallen/nestjs-google-pubsub#readme
@p-fedyukovich Sure
message example
{ "broker": "Smart Prime Group Ltd.", "time": "2022-02-14T00:21:01.137Z", "symbol": "SPA35", "ask": 50.25, "bid": 60.50, "volume": 6500, "publisherTime": "2022-02-14T00:21:01.137Z" }
here is my topic schema
{ "type": "record", "name": "Avro", "fields": [ { "name": "broker", "type": "string" }, { "name": "time", "type": "string" }, { "name": "symbol", "type": "string" }, { "name": "ask", "type": "double" }, { "name": "bid", "type": "double" }, { "name": "volume", "type": "double" }, { "name": "publisherTime", "type": "string" } ] }
p.s I tried with this lib and it's working fine https://github.com/crallen/nestjs-google-pubsub#readme
Your message data format is wrong because it should have metadata for correct selecting message handler. If you use your own message dispatcher it should produce message in such format
{
"pattern": "notifications",
"eventId": "any string value for that message which keeps idemopotency",
"data": "Your message payload"
}
Thank you for reply. So what changes exactly I need to make in my message and schema to make it work?
I provided the message structure, you should update your message producer to fit the message structure
Hi @p-fedyukovich I have trouble publishing the message, could you please provide a working example here or to the ReadMe file?
Hi @p-fedyukovich I have trouble publishing the message, could you please provide a working example here or to the ReadMe file?
Hi, there are examples in test files.
import {
Body,
Controller,
HttpCode,
OnApplicationShutdown,
Post,
Query,
} from '@nestjs/common';
import {
ClientProxy,
EventPattern,
MessagePattern,
} from '@nestjs/microservices';
import { GCPubSubClient } from '../../lib';
@Controller()
export class GCPubSubController implements OnApplicationShutdown {
client: ClientProxy;
constructor() {
this.client = new GCPubSubClient({
client: {
apiEndpoint: 'localhost:8681',
projectId: 'microservice',
},
});
}
onApplicationShutdown(signal?: string) {
return this.client.close();
}
@Post('notify')
async sendNotification(): Promise<any> {
return this.client.emit('notification', true);
}
}
Привет @p-fedyukovichУ меня возникли проблемы с публикацией сообщения. Не могли бы вы предоставить рабочий пример здесь или в файле ReadMe?
Привет, в тестовых файлах есть примеры.
import { Body, Controller, HttpCode, OnApplicationShutdown, Post, Query, } from '@nestjs/common'; import { ClientProxy, EventPattern, MessagePattern, } from '@nestjs/microservices'; import { GCPubSubClient } from '../../lib'; @Controller() export class GCPubSubController implements OnApplicationShutdown { client: ClientProxy; constructor() { this.client = new GCPubSubClient({ client: { apiEndpoint: 'localhost:8681', projectId: 'microservice', }, }); } onApplicationShutdown(signal?: string) { return this.client.close(); } @Post('notify') async sendNotification(): Promise<any> { return this.client.emit('notification', true); } }
What is apiEndpoint: 'localhost:8681' responsible for, how to use it?
What is apiEndpoint: 'localhost:8681' responsible for, how to use it?
This is yours pubsub
server address
What is apiEndpoint: 'localhost:8681' responsible for, how to use it?
This is yours
pubsub
server address
From the example above, it's not quite clear where I'm creating a microservice with this port.
I would be very grateful if you could tell me where I can see a working example of server and client operation. It seems to me that these examples do not quite explain everything
Hi I tried to use the library but I keep getting "There is no matching event handler defined in the remote service. Event pattern: undefined" error when a new message arrives.
my code is like this.
main.ts
Then in app.controller
nestjs:8.2.5 (I tried with 8.0.0 as well) @google-cloud/pubsub: 2.19.4 nestjs-google-pubsub-microservice: 2.2.0