[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Paho Mqtt C Client : message received callback is getting called multiple times.

Some suggestions:

1) Make sure that your callback is returning a true value (not zero) to indicate that the message has been processed.Â

2) Your trace output shows messages arriving on topics which are not printed out successfully. What is the source of these messages? Why aren't the topics printing?

3) Check the values of msgid and dup in the message data in the callback to see if different messages are being delivered, or duplicates of the same one.

Ian

On 12/07/2017 10:03, vikas sharma wrote:
Hi

Iam using Paho Mqtt C Client.I have subscribed on a particular topic like mqtt/TestTopic/# with QoS 1. Now when i am publishing using an mqttfx application on a topic like mqtt/TestTopic/Name the callback function in my application is getting called infinitly.

Providing below some details regarding my code.

Default connection initializer value.
#define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 4, 60, 1, 10, NULL, NULL, NULL, 30, 0,\
NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60}

MQTTAsync_setCallbacks(client, NULL, connlost, messageArrivedCb, NULL);

conn_opts.keepAliveInterval = 5;
conn_opts.cleansession = 1;
conn_opts.automaticReconnect = 1;
conn_opts.> conn_opts.> conn_opts.context = client;

int messageArrivedCb(void* context, char* topicName, int topicLen,
ÂÂÂÂÂÂÂ MQTTAsync_message* m)

{
ÂÂÂ int i;
ÂÂÂ char* payloadptr;

ÂÂÂ DEBUG("Message Arrived for Topic[%s]\n",topicName);
ÂÂÂ payloadptr = m->payload;
ÂÂÂ for(i=0; i<m->payloadlen; i++)
ÂÂÂ {
ÂÂÂÂÂÂÂ putchar(*payloadptr++);
ÂÂÂ }
ÂÂÂ putchar('\n');
ÂÂÂ
//ÂÂÂ DEBUG("Payload[%s]\n",(char*)m->payload);
ÂÂÂ MQTTAsync_freeMessage(&m);
ÂÂÂ MQTTAsync_free(topicName);
ÂÂÂÂÂÂÂ return SUCCESS;
}

The issue we are facing is that the Call back for message received on subscribed topic is getting called multiple times even though a message is published only once.
I am also getting below prints.

20170712 122804.108 4 ser01 <- PUBLISH msgid: 1 qos: 1 retained: 0 payload: hi buddy
20170712 122804.108 4 ser01 -> PUBACK msgid: 1 (0)
Debug: Message Arrived for Topic[mqtt/testTopic/LCD]
hi buddy
Debug: Message Arrived for Topic[ï ]

20170712 122804.108 Failed to remove heap item at file src/MQTTAsync.c line 1617
20170712 122804.108 Failed to remove heap item at file src/MQTTAsync.c line 1618
20170712 122804.108 Failed to remove heap item at file src/MQTTAsync.c line 1627
20170712 122808.985 4 ser01 <- PUBLISH msgid: 2 qos: 1 retained: 0 payload: hi buddy
20170712 122808.985 4 ser01 -> PUBACK msgid: 2 (0)
Debug: Message Arrived for Topic[ï ]
hi buddy
20170712 122808.985 Failed to remove heap item at file src/MQTTAsync.c line 1627
20170712 122817.215 4 ser01 -> PINGREQ (0)
20170712 122818.094 4 ser01 <- PINGRESP
Debug: Message Arrived for Topic[ï ]


Can anybody tell how to avoid this?


_______________________________________________
paho-dev mailing list
paho-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/paho-dev

-- 
Ian Craggs
icraggs@xxxxxxxxxx                 IBM United Kingdom
Paho Project Lead; Committer on Mosquitto