moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

Use Mosquitto in Mosca. #649

Closed a244096658 closed 7 years ago

a244096658 commented 7 years ago

I include Mosquitto in Mosca. But the pub/sub messaging still works fine even without adding Mosquitto to the backend.

So I am wondering what is the reason and benefit to use Mosquitto as a backend for Mosca? I went through the wiki tutorials and knew that using MongoDB is for offline/retain message purpose. But I still do not understand the logic to use another broker e.g: Mosquitto inside Mosca. Can Mosca perform as a broker itself?

My code to use Mosquitto is here:

var pubsubsettings = { type: 'mqtt', json: false, mqtt: require('mqtt'), host: '127.0.0.1', port: 1883 }; var moscaSettings = { port: 1884, //mosca (mqtt) port backend: pubsubsettings, //pubsubsettings is the object we created above }; var server = new mosca.Server(moscaSettings); server.on('ready', setup);

mcollina commented 7 years ago

Yes, the Mosquitto is similar to mosquitto's one. You can back one mosquitto with another.

It is not very much useful in practice for Mosca, use MongoDB or Redis.

a244096658 commented 7 years ago

I still have the following questions, hope can get help from you:

  1. I now use Mosquitto as backend for Mosca, and my Mosquitto can receive the published data. Does it mean Mosquitto will overwrite Mosca that all the sub/pub message are processed through Mosquitto?

  2. It is not very much useful in practice for Mosca, use MongoDB or Redis.

So it is more practical to use MongoDB or Redis instead of using Mosquitto? And reason to use MongoDB as backend is to store published data?

  1. Do I need to use ascoltatore npm module together with Mosca?

Thanks in advance!!

mcollina commented 7 years ago

Can you please rephrase the question 1? I don't understand.

You should use Redis (preferred) or MongoDB.

a244096658 commented 7 years ago

For question 1, I mean: Does Mosca just perform as a container when I use Mosquitto as a backend? So that Mosquitto will carry all the mqtt service.

Thanks for your response.

mcollina commented 7 years ago

Yes, but the offline messages will still be stored in mosca (redis or mongodb persistence).