mop icon indicating copy to clipboard operation
mop copied to clipboard

Are there any plans to support hooks such as connected, disconnected, authenticate?

Open liweiv opened this issue 4 years ago • 12 comments

Is your enhancement request related to a problem? Please describe. Are there any plans to support hooks such as connected, disconnected, authenticate? Describe the solution you'd like In IoT application scenarios, we often pay attention to when the device is connected or disconnected, as well as the time and result of device authentication. Can the corresponding hook be enabled in a configurable way to convert the message to the pulsar protocol? The back-end program can monitor when the device is connected or disconnected by subscribing to the configured topic

liweiv avatar Dec 24 '21 14:12 liweiv

@liweiv

Do you want MOP to push events to a specific topic, and then you can use pulsar or mqtt client to monitor it?

mattisonchao avatar Dec 25 '21 00:12 mattisonchao

@mattisonchao Yes, I want to use pulsar protocol to monitor it. This is very useful for backend server program to handle some business logical.

liweiv avatar Dec 25 '21 05:12 liweiv

@liweiv

I think it's a good suggestion. what do you think about it ? @Technoboy-

mattisonchao avatar Dec 25 '21 07:12 mattisonchao

Hi @liweiv, this is really a good suggestion, but I'm not sure if some other MQTT implementations that support this feature?
We can check this feature first and then make a MIP to discuss. @mattisonchao

Technoboy- avatar Dec 27 '21 03:12 Technoboy-

@Technoboy-

Ok, i will work on it.

mattisonchao avatar Dec 27 '21 06:12 mattisonchao

@Technoboy- This feature can be found in emqx.

liweiv avatar Dec 27 '21 09:12 liweiv

@liweiv

Do you mean this feature in emqx ?

the link is : https://docs.emqx.io/en/enterprise/v4.4/advanced/hooks.html#callback-function

mattisonchao avatar Dec 28 '21 05:12 mattisonchao

@Technoboy- @liweiv

I think we current do not need to support hook, because MOP just is a protocol plugin for pulsar. add hook will be too complicated

But we can support system event topic to push event by json format.

What do you guys think about this.

If agree, i will submit a MIP.

mattisonchao avatar Dec 28 '21 05:12 mattisonchao

@Technoboy- Ok, I think the way of event topic can solve problems。

liweiv avatar Dec 28 '21 06:12 liweiv

But we can support system event topic to push event by json format.

make sense.

liangyuanpeng avatar Dec 28 '21 06:12 liangyuanpeng

@liweiv @liangyuanpeng @Technoboy-

Ok, I will submit a MIP.

mattisonchao avatar Dec 28 '21 06:12 mattisonchao

@liweiv You can track connected status through LWT which is part of the MQTT standard for basically this exact reason. Typical implementation would be that an MQTT client sets up an LWT message which is fired by the broker when the keep alive mechanism fails signaling that the connection is likely dead. Expected behavior here is that you'd fire a message on client disconnect, similarly on graceful disconnect you'd just send a message before you disconnect. To handle connect events just publish connect events when you connect, or a more robust approach would be to have your connection status message be retained, so that you can have the client itself subscribe on it's connection topic and always send a conneced status in response to any disconnected status messages. This way if LWT fires from another broker, and you reconnected to a different broker and publish a connected message before the LWT fires, you can correct the potential race condition that occurs. So this mechanism is baked into the MQTT standard, and is a very common means to do the exact type of connection tracking you're talking about.

Unfortunately LWT in MoP does not behave correctly, as it only publishes LWT events to MQTT subscribers, and LWTs currently do not reach Pulsar topics at all. I have proposed a fix for this, however it's gotten no response in several months: https://github.com/streamnative/mop/pull/943

tsturzl avatar Dec 01 '23 19:12 tsturzl