YOUSEFUL / DELPHI / COMPONENTS

TMqttQoS

Quality of service: at most once, at least once, exactly once.

Enumeration Unit Atlas.MqttCodec · Product Atlas MQTT

Description

pascal
TMqttQoS = (qosAtMostOnce, qosAtLeastOnce, qosExactlyOnce);

The ordinal values 0, 1 and 2 are the MQTT quality levels. Declared in Atlas.MqttCodec, so add that unit to uses wherever you name a value. A message is delivered at the lower of the quality it was published with and the quality of the subscription.

Members

MemberKindWhat it does
qosAtMostOncevalueQuality 0: sent once, never acknowledged or repeated.
qosAtLeastOncevalueQuality 1: repeated until the receiver answers PUBACK.
qosExactlyOncevalueQuality 2: a four-step exchange (PUBLISH, PUBREC, PUBREL, PUBCOMP) that delivers exactly once.

Values

qosAtMostOnce value

qosAtMostOnce

Quality 0: sent once, never acknowledged or repeated. Cheap, and lost if the connection drops at the wrong moment. TAtlasMqttClient.Publish refuses it while offline.

qosAtLeastOnce value

qosAtLeastOnce

Quality 1: repeated until the receiver answers PUBACK. It may arrive more than once, for example after a reconnect.

qosExactlyOnce value

qosExactlyOnce

Quality 2: a four-step exchange (PUBLISH, PUBREC, PUBREL, PUBCOMP) that delivers exactly once. Atlas MQTT suppresses a repeated quality-2 message on both the client and the broker side.

Examples

A quality from a stored setting

The values are ordinals 0 to 2; anything else is refused.

pascal
uses
  Atlas.MqttCodec;

function QualityFromSetting(Value: Integer): TMqttQoS;
begin
  if (Value < Ord(Low(TMqttQoS))) or (Value > Ord(High(TMqttQoS))) then
    raise EAtlasMqttError.CreateFmt('Quality %d does not exist in MQTT 3.1.1', [Value]);
  Result := TMqttQoS(Value);
end;

TAtlasMqttClient · TMqttPacket

Also in Atlas MQTT

TAtlasMqttClient · TAtlasMqttBroker