bluerhinos / phpMQTT

a simple php class to connect/publish/subscribe to a MQTT broker
Other
773 stars 460 forks source link

Add PUBREL for QOS 2 support #22

Closed rwestergren closed 7 years ago

rwestergren commented 8 years ago

MQTT client QOS 2 flow requires:

QOS 2 - exactly one delivery

Normal Flow

client sends a QoS 2 PUBLISH message and stores in Persistent Outbox
broker replies with PUBREC
client sends PUBREL
broker responds with PUBCOMP
client receives PUBCOMP and deletes message from Persistent Outbox
optonc commented 8 years ago

Why it doesn't work for me? I am using a emqtt broker. I wish to send command (publish) by Qos = 2.

rwestergren commented 8 years ago

This code tests fine using a demo broker. For example:

// Test Broker
$address = "broker.mqttdashboard.com";
$port = 1883;
$clientid = uniqid();

$mqtt = new phpMQTT($address, $port, $clientid);

$mqtt->connect();
$mqtt->publish("testtopic/1", "Test 123", 2);
$mqtt->close();

You may need to troubleshoot a raw packet capture - the issue is likely with your broker.

bluerhinos commented 7 years ago

Sorry its taken so long to look at this, but I am back using MQTT now.

I am not going to merge this as its not really supporting QoS 2 as its not waiting for a PUBREC before sending the PUBREL but I will look into how I can have an 'Outbox' in phpMQTT to support QoS

rwestergren commented 7 years ago

Great point - this just fit a specific need for a project I was working on. Closed!