nest icon indicating copy to clipboard operation
nest copied to clipboard

MQTT microservice published QOS 2 tagged messages as QOS 0

Open ChristiaanWillemsen opened this issue 3 years ago • 2 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

Creating a record with QOS 2 sending it out and via emit leads to actually sending a QOS 0 message:

const record = new MqttRecordBuilder(event).setQoS(2).build();
this.mqttClient.emit(config.mqttTopic, record);

Minimum reproduction code

http://foo.bar

Steps to reproduce

  1. define a MQTT client in your @Module via ClientsModule.register
  2. inject the client as a ClientProxy in your service
  3. call some code to send a message:
const event = {"foo":"bar"}
const record = new MqttRecordBuilder(event).setQoS(2).build();
this.mqttClient.emit(config.mqttTopic, record);

Possibly there is one additional thing, I use a serializer to get rid of the default data structure:

{
   serializer: new MQTTDataSerializer()
}
export class MQTTDataSerializer implements Serializer {
  serialize(value: any): OutgoingResponse {
    return value.data.data;
  }
}

Expected behavior

I would expect the message to be sent as QOS 2, but it's not.

Package

  • [ ] I don't know. Or some 3rd-party package
  • [ ] @nestjs/common
  • [ ] @nestjs/core
  • [X] @nestjs/microservices
  • [ ] @nestjs/platform-express
  • [ ] @nestjs/platform-fastify
  • [ ] @nestjs/platform-socket.io
  • [ ] @nestjs/platform-ws
  • [ ] @nestjs/testing
  • [ ] @nestjs/websockets
  • [ ] Other (see below)

Other package

No response

NestJS version

9.0.11

Packages versions

    "@nestjs/axios": "^0.1.0",
    "@nestjs/common": "^9.0.11",
    "@nestjs/config": "^2.2.0",
    "@nestjs/core": "^9.0.11",
    "@nestjs/microservices": "^9.0.11",
    "@nestjs/platform-express": "^9.0.11",
    "@nestjs/schedule": "^2.1.0",

Node.js version

v16.13.0

In which operating systems have you tested?

  • [X] macOS
  • [ ] Windows
  • [X] Linux

Other

No response

ChristiaanWillemsen avatar Oct 03 '22 07:10 ChristiaanWillemsen

What version of mqtt do you use?

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

kamilmysliwiec avatar Oct 03 '22 07:10 kamilmysliwiec

MQTT version 3.1.1

ChristiaanWillemsen avatar Oct 03 '22 07:10 ChristiaanWillemsen

There must be something wrong with your setup. If you look at this test https://github.com/nestjs/nest/blob/master/integration/microservices/e2e/mqtt-record-builder.spec.ts, you'll see that we're actually checking if setting QOS has an effect (note the difference is that we're using the eclipse-mosquitto image MQTT 5.0 too).

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.

kamilmysliwiec avatar Oct 25 '22 09:10 kamilmysliwiec