Giter VIP home page Giter VIP logo

Comments (10)

p-fedyukovich avatar p-fedyukovich commented on June 19, 2024

Hi, could you provide pubsub message example which client sends?

from nestjs-google-pubsub-microservice.

RezaRahmati avatar RezaRahmati commented on June 19, 2024

@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

from nestjs-google-pubsub-microservice.

p-fedyukovich avatar p-fedyukovich commented on June 19, 2024

@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"
}

from nestjs-google-pubsub-microservice.

RezaRahmati avatar RezaRahmati commented on June 19, 2024

Thank you for reply.
So what changes exactly I need to make in my message and schema to make it work?

from nestjs-google-pubsub-microservice.

p-fedyukovich avatar p-fedyukovich commented on June 19, 2024

I provided the message structure, you should update your message producer to fit the message structure

from nestjs-google-pubsub-microservice.

KristianPu avatar KristianPu commented on June 19, 2024

Hi @p-fedyukovich I have trouble publishing the message, could you please provide a working example here or to the ReadMe file?

from nestjs-google-pubsub-microservice.

p-fedyukovich avatar p-fedyukovich commented on June 19, 2024

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);
  }
}

from nestjs-google-pubsub-microservice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.