YOUSEFUL / DELPHI / COMPONENTS

TAtlasMqttPacketEvent

The type of TAtlasMqttClient.OnPublished: the broker acknowledged a message.

Type Unit Atlas.MqttClient · Product Atlas MQTT

Description

pascal
TAtlasMqttPacketEvent = procedure(Sender: TObject; PacketId: Word) of object;

PacketId is the identifier that Publish returned for a message at quality 1 or 2. An identifier becomes free once its message is acknowledged and is reused later, so match it to your own records only while the message is pending.

This type has no members of its own beyond those listed in its description.

Examples

Track messages until the broker confirms them

Called on the main thread with SynchronizeEvents True, so the dictionary is only ever touched by one thread.

pascal
uses
  System.Generics.Collections, Atlas.MqttCodec, Atlas.MqttClient;

type
  TDeliveryTracker = class
    Pending: TDictionary<Word, string>;
    procedure Send(Client: TAtlasMqttClient; const Topic, Text: string);
    procedure ClientPublished(Sender: TObject; PacketId: Word);
  end;

procedure TDeliveryTracker.Send(Client: TAtlasMqttClient; const Topic, Text: string);
begin
  Pending.AddOrSetValue(Client.Publish(Topic, Text, qosExactlyOnce), Text);
end;

procedure TDeliveryTracker.ClientPublished(Sender: TObject; PacketId: Word);
begin
  Pending.Remove(PacketId);  // PUBCOMP arrived: the broker has it, exactly once
end;

TAtlasMqttClient

Also in Atlas MQTT

TAtlasMqttClient · TAtlasMqttBroker