← Back to team overview

mosquitto-users team mailing list archive

Re: Mosquitto+Python+MySQL+APNS

 

Hi Yun,

> 1. what's the best practice to connect Mosquitto broker with the MySQL to
> make sure: all messages are stored in the database? Ideally, all message
> sent to server should be stored in the db before they are distributed, to
> ensure the data security.

At the moment you have to write an MQTT client that subscribes to the
appropriate topics and then stores the messages in your database. You
can ensure the messages are stored in the database before being
distributed by carefully separating the topics that clients publish
and subscribe to. Your server side processing then acts as in the
"subscribe, receive, process, republish" pattern - it receives the
incoming message, saves it to the database and then republishes it to
the appropriate recipients. You could even split this up - one (or
more, depending on how you arrange it) server side client for
processing the incoming messages and saving them to the database, then
other server side clients to distribute the messages.

> 2. when the server know one client is not active/connected, the server
> should call the APNS service to send the notice to the client. Should this
> process happen in the API or from the broker?

This is where you will want to make use of the "last will and
testament" (or just "will") feature. When your client connects, it
sets up a Will message with the broker. When the client disconnects
unexpectedly (i.e. without sending a DISCONNECT) the broker publishes
the Will. A common way of using this is to publish "1" to a topic e.g.
status/<client id> when the client connects. The client also set up
the Will to publish a "0" to status/<client id> on unexpected
disconnect. Your server side processing can then subscribe to status/#
to determine the current connection status of all clients and use this
information for determining how to distribute the message.

> 3. for the iPhone wrapper of the mosquitto client, I checked Marquette , is
> this wrapper compatible with the latest version of Mosquitto 1.0.2

>From what I can see, the last commit to Marquette was 8 months ago, so
unfortunately no it isn't compatible with 1.0.2. I would point out
that libmosquitto compiles just fine under Objective C, although of
course it isn't an Objective C interface.

Cheers,

Roger

> I know this is quite complicated issue, but really hope can get some advice
> on how to approach.
>
> thanks a lot!
>
> -Horace
>
> --
> Mailing list: https://launchpad.net/~mosquitto-users
> Post to     : mosquitto-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~mosquitto-users
> More help   : https://help.launchpad.net/ListHelp
>


Follow ups

References