eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.12k stars 2.41k forks source link

Cannot create a plugin to handle messages received through bridge #3163

Open satel-kalletuulos opened 1 week ago

satel-kalletuulos commented 1 week ago

Mosquitto version: 2.0.18 Target environment: Yocto 4.0 (Kirkstone)

The device A running Mosquitto broker establishes bridge to device B. Purpose is to create a plugin to modify messages received through bridge.

I'm experimenting with the sample plugin from Mosquitto repository: https://github.com/eclipse-mosquitto/mosquitto/blob/v2.0.18/plugins/payload-modification/mosquitto_payload_modification.c

I added debug print to callback_message function so I can see, when that message is called, as follows:

static int callback_message(int event, void *event_data, void *userdata)
{
    struct mosquitto_evt_message *ed = event_data;
    char *new_payload;
    uint32_t new_payloadlen;

    UNUSED(event);
    UNUSED(userdata);

    printf("Plugin callback message with topic %s\n", ed->topic);

System's /etc/mosquitto/mosquitto.conf file is as follows:

include_dir /etc/mosquitto/conf.d

On /etc/mosquitto/conf.d directory, there are following configuration files:

01-defaults.conf - contains just row per_listener_settings true

10-listener-all.conf - contains definitions for the default listener, currently following:

listener 1883
allow_anonymous true

20-default-bridge.conf - contains following:

connection default-bridge
address 10.10.100.10
topic # both 0 "" mydevice/

30-sample-plugin.conf - contains following:

listener 1884
allow_anonymous true
plugin /usr/lib/mosquitto_dynamic/sample_plugin.so

Notice that the plugin configuration file has to have additional listener, as otherwise it would open default listener for port 1883 and it would conflict for the existing listener.

For testing and debugging, Mosquitto broker is started with command line: mosquitto -c /etc/mosquitto/mosquitto.conf From debug prints, it can be seen that the sample plugin is not called for messages arriving through bridge or for messages arriving from default listener on port 1883. Plugin is called only for messages arriving from port 1884.

Question: How can plugin be configured so that it would called for ALL messages, arriving from all ports and also from bridge?

Daedaluz commented 1 week ago

since per-listener settings is true, perhaps adding plugin /usr/lib/mosquitto_dynamic/sample_plugin.so to the 1883 listener helps?

satel-kalletuulos commented 1 week ago

It does not help. The plugin is called only for messages sent through that specific listener.