Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[mosquitto-dev] publish in the message callback

Hi,
I want to publish a message to topic B when I receive a message on topic A.
In the callback of topic A, I use mosquitto_publish("topics/B"....) and it works very well.

My problem is the message arrives at topic B only when I return from the callback.

void on_message(struct mosquitto *mosq, void *obj, const struct mosquitto_message *msg)
{
        const char *payload = "0000000000000000000000000000";
        printf("send new msg to B");
        mosquitto_publish(mosq, NULL, "topic/B", strlen(payload), payload, 1, 0);
        printf ("sleep 10");
        sleep(10);
        printf ("wakeup");
}

My other process subscribed to B received the message but onlt after 10s (=when A print "wakeup")

Why is it working like this and how to publish from A immediately ?

I put sleep(10) for example but in reality it's a call to multiple functions in my process which take time to execute.

Thanks.


Back to the top