EnSync Engine Documentation Help

UNSUB Command Overview

Purpose

The UNSUB command allows clients to completely remove a subscription to a specific event type. Unlike the PAUSE command which temporarily halts event processing, UNSUB permanently stops the delivery of events of the specified type until a new subscription is created.

Use Cases

Resource Optimization

When a client no longer needs to process certain event types, unsubscribing frees up resources on both the client and server sides.

Dynamic Configuration

Applications with changing requirements can dynamically adjust their event subscriptions based on current needs or user configurations.

Cleanup

Before disconnecting or during application shutdown, clients can unsubscribe from all event types to ensure proper cleanup of server-side resources.

Access Control

When a client's permissions change, they may need to unsubscribe from event types they no longer have access to.

Implementation Details

The UNSUB command works by:

  1. Validating that the client has an active subscription to the specified event type

  2. Removing the client's subscription from the subscription registry

  3. Returning any in-process events for this client and event type to the pending queue

  4. Cleaning up any associated metadata and resources

Security Considerations

  • Clients can only unsubscribe from event types they are currently subscribed to

  • The CLIENT_ID must match an active connection

  • Unsubscribing does not affect other clients' subscriptions to the same event type

Performance Impact

  • The UNSUB command is a lightweight operation with minimal performance impact

  • Events that were in the client's processing queue are returned to the pending queue

  • Unsubscribing reduces the overall load on the system by eliminating unnecessary event processing

  • SUB: Subscribes to an event type

  • PAUSE: Temporarily stops event processing

  • CONTINUE: Resumes event processing after a pause

Best Practices

  • Unsubscribe from event types that are no longer needed to optimize resource usage

  • Use PAUSE instead of UNSUB for temporary interruptions in event processing

  • Implement proper error handling for cases where unsubscribing fails

  • Consider implementing automatic unsubscribe for inactive clients to prevent resource leaks

  • Always unsubscribe from all event types before disconnecting a client

Last modified: 07 October 2025