Code Monkey home page Code Monkey logo

Comments (10)

rahulbhanushali avatar rahulbhanushali commented on July 20, 2024

With a minor tweak to EventEmitter settings, this can be avoided. More on this here.

To solve the issue you could add this line to your index file:

process.setMaxListeners(0)

If that doesn't solve the problem, you could also add this line in the connackSent event handler:

client.conn._maxListeners = 500;

from aedes.

GavinDmello avatar GavinDmello commented on July 20, 2024

@cordovapolymer You can try bumping the concurrency param in the Aedes options to a sufficient amount to avoid the warning, but in which ways messages shouldn't be dropped.

from aedes.

mcollina avatar mcollina commented on July 20, 2024

can you please a testing script so we can easily reproduce?

from aedes.

cordovapolymer avatar cordovapolymer commented on July 20, 2024

@rahulbhanushali tryed process.setMaxListeners(0), seems that the warning was suppressed, but messages are still not delivered.
@GavinDmello tried setting concurrency param to 1000 and 10000, nothing changed.

@mcollina can you please a testing script so we can easily reproduce?

updated to run as node mqtt-test.js, download a 4MB image for test

// mqtt-test.js
/*jslint node: true, esversion: 6 */
'use strict';
console.log("loading mqtt-test module");

var MqttTest = class MqttTest {
    constructor() {
      console.log("instanciating mqtt module");
      this.mqtt = require('mqtt');
      this.client  = this.mqtt.connect('mqtt://broker');
      var fs = require('fs');
      var data = {};

      function base64_encode(file) {
          // read binary data
          var bitmap = fs.readFileSync(file);
          // convert binary data to base64 encoded string
          return new Buffer(bitmap).toString('base64');
      }

      var base64str = base64_encode('msg-1-fc-40.jpg');
      data.message = base64str;
      data.topic = 'message/topic';
      var jsonMessage = JSON.stringify(data.message);
      if(jsonMessage.length >= 2048){
        var messageChunks = this.chunkSubstr(jsonMessage, 2048);
        var messageId = Math.random().toString(36).substr(2, 16);
        var chunkNumber = 0;
        var totalChunks = messageChunks.length;
        console.log('totalChunks'+totalChunks);
        messageChunks.forEach(function(messageChunk) {
          var chunk = {data: {}};
          chunk.partial = {};
          chunk.partial.number = chunkNumber;
          chunk.partial.id = messageId;
          chunk.partial.total = totalChunks;
          chunk.data = messageChunk;
          chunk.topic = jsonMessage.topic;
          this.client.publish(data.topic, JSON.stringify(chunk), {'qos': 2});
          chunkNumber++;
        }, this);
      }
      else{
        this.client.publish(data.topic, jsonMessage, {'qos': 2});
      }

      this.client.on('connect', function () {
        console.log("MQTT connected");
      }.bind(this));
      console.log("finished instanciating mqtt module");
    }

    chunkSubstr(str, size) {
      var numChunks = Math.ceil(str.length / size),
          chunks = new Array(numChunks);

      for(var i = 0, o = 0; i < numChunks; ++i, o += size) {
        chunks[i] = str.substr(o, size);
      }

      return chunks;
    }
};

var myMqttTest = new MqttTest();
console.log("loaded mqtt-test module");

from aedes.

GavinDmello avatar GavinDmello commented on July 20, 2024

@cordovapolymer I wasn't able to detect any problem at my end. Is the receiver is offline when these messages are published ? If so, try using clean false. Also it would be a good idea to defer your publishes to on connect-Just a suggestion.

from aedes.

mcollina avatar mcollina commented on July 20, 2024

@cordovapolymer it seems your code is supposed to be used required by some other module? Can you make it so that we can just run it?

It would be easier to reproduce the problem.

from aedes.

cordovapolymer avatar cordovapolymer commented on July 20, 2024

@GavinDmello, @mcollina , I've updated the code to run standalone. Narrowing the problem- as I've found out 2773 messages are successfully received via mqtt protocol, but are not via websocket.
I'm using standart mqtt.js client.
When changing maximum message length in if(jsonMessage.length >= 2048){ var messageChunks = this.chunkSubstr(jsonMessage, 2048); to 204800 bytes, 28 messages are successfully received both via mqtt and websocket.

from aedes.

mcollina avatar mcollina commented on July 20, 2024

On my tests, I am getting exactly 2773 messages over ws. Can you please a full project that exhibit this issue? Is this happening on the browser?

from aedes.

cordovapolymer avatar cordovapolymer commented on July 20, 2024

@mcollina
I will publish it a bit later because I'll have to prepare it, last week I've been trying to solve another issue which I'm going to publish right now.

from aedes.

mcollina avatar mcollina commented on July 20, 2024

Ping, any update on the example to replicate?

from aedes.

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.