moscajs / mosca

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

How do two mosca brokers communicate? #505

Closed shansjlin closed 8 years ago

shansjlin commented 8 years ago

Suppose there are two clients called ClientA and ClientB, and there are two mosca brokers called brokerA and brokerB. And suppose brokerA is deployed on machine_A, and brokerB is deployed on machine_B. ClientA and ClientB use the same topic. ClientA publish message to the brokerA. ClientB subscribe topic from brokerB. My Question is: If ClientA publish a message to brokerA, how can ClientB get the message from brokerB? Should we establish a tcp connection between brokerA and brokerB?

If I want to deploy many brokers on different machines for the disaster recovery, what am I supposed to do?

Thank you

behrad commented 8 years ago

If ClientA publish a message to brokerA, how can ClientB get the message from brokerB? Should we establish a tcp connection between brokerA and brokerB?

it depends to the backend and persistence you choose. With Redis you can achieve this, you only need to configure mosca to run with redis backend & redis persistence.

Things go this way: A publishes to moscaA, mosca publishes A's publish to all mosca instances (including moscaB) using redis PUB/SUB, moscaB receives the publish, matches B, and forwards the message to B :)

For offline messages when QOS>0 there's a bit more to it.

ruizeng commented 8 years ago

@behrad If this works when using rabbitmq backend?

behrad commented 8 years ago

I haven't used mosca with rabbitmq, but it uses AMQP to sit on top of RabbitMQ, and https://github.com/mcollina/ascoltatori/blob/master/lib/amqp_ascoltatore.js shows that YES, it should work :)

ruizeng commented 8 years ago

@behrad thanks. I'll make a test to verify that.

shansjlin commented 8 years ago

@behrad thanks