TsgcWSPServer_WAMPEvents › OnBeforeSubscription

OnBeforeSubscription Event

Fires when a client sends a SUBSCRIBE frame, giving the server the chance to accept or reject the subscription.

Syntax

property OnBeforeSubscription: TsgcWSBeforeSubscriptionEvent;
// TsgcWSBeforeSubscriptionEvent = procedure(Connection: TsgcWSConnection; const Subscription: String; var Accept: Boolean) of object

Default Value

Remarks

Subscription is the topic URI the client is asking to join (already resolved against any prefix previously registered with OnPrefix). Accept is set to True by default, meaning the broker will register the client as a subscriber and start forwarding EVENT messages. Set it to False to silently drop the SUBSCRIBE — the broker will not add the client to the topic and no confirmation is sent back (WAMP v1 has no SUBSCRIBED frame). Typical use is access control: check the authenticated identity attached to Connection against an ACL, namespace policy or rate limit.

Example


procedure TForm1.WAMPServerBeforeSubscription(Connection: TsgcWSConnection;
  const Subscription: String; var Accept: Boolean);
begin
  // allow public topics, reject admin channels for non-admin clients
  Accept := not StartsText('http://example.com/admin/', Subscription);
  Memo1.Lines.Add(Format('[%s] SUBSCRIBE %s -> %s',
    [Connection.Guid, Subscription, BoolToStr(Accept, True)]));
end;

Back to Events