Yayımla/abone ol deseni (pub/sub olarak da bilinir), geleneksel istemci-sunucu mimarisine bir alternatif sunar. İstemci-sunucu modelinde, bir istemci doğrudan bir uç noktayla iletişim kurar. Pub/sub modeli bir mesaj gönderen istemciyi (yayıncı), mesajları alan istemci veya istemcilerden (aboneler) ayırır. Yayıncılar ve aboneler birbiriyle asla doğrudan temas kurmaz. Aslında, diğerinin var olduğunun bile farkında değildirler. Aralarındaki bağlantı üçüncü bir bileşen (broker) tarafından yönetilir. Broker'ın görevi, gelen tüm mesajları filtrelemek ve bunları abonelere doğru şekilde dağıtmaktır.
TsgcWSPClient_MQTT ile Mesaj Yayınlayabilir ve Konulara Abone Olabilirsiniz.
Başarılı bir bağlantıdan sonra "topic1" konusuna abone olun.
oClient := TsgcWebSocketClient.Create(nil);
oClient.Host := 'test.mosquitto.org';
oClient.Port := 8080;
oMQTT := TsgcWSPClient_MQTT.Create(nil);
oMQTT.Client := oClient;
oClient.Active := True;
procedure OnMQTTConnect(Connection: TsgcWSConnection; const Session: Boolean; const ReasonCode: Integer;
const ReasonName: string; const ConnectProperties: TsgcWSMQTTCONNACKProperties);
begin
oMQTT.Subscribe('topic1');
end;
"topic1"in tüm abonelerine bir mesaj yayınlayın
oClient := TsgcWebSocketClient.Create(nil);
oClient.Host := 'test.mosquitto.org';
oClient.Port := 8080;
oMQTT := TsgcWSPClient_MQTT.Create(nil);
oMQTT.Client := oClient;
oClient.Active := True;
procedure OnMQTTConnect(Connection: TsgcWSConnection; const Session: Boolean; const ReasonCode: Integer;
const ReasonName: string; const ConnectProperties: TsgcWSMQTTCONNACKProperties);
begin
oMQTT.Publish('topic1', 'Hello Subscribers topic1');
end;