barrel_sub (barrel_docdb v1.1.1)

View Source

barrel_sub - Path subscription manager for barrel_docdb

Manages MQTT-style path subscriptions for document changes. Subscribers receive notifications when documents matching their patterns are modified.

Pattern examples:

   "users/+/profile" - matches users/123/profile, users/abc/profile
   "orders/#"        - matches orders/123, orders/123/items/1
   "config"          - matches exactly config

Subscriptions are ephemeral - tied to subscriber process lifetime.

Summary

Functions

List all subscriptions for a database (for debugging)

Find all subscriber PIDs matching the given paths. Paths should be slash-separated binaries like "users/123/name".

Start the subscription manager

Stop the subscription manager

Subscribe to document changes matching a pattern Returns a subscription reference that can be used to unsubscribe

Unsubscribe using the subscription reference

Types

att_info/0

-type att_info() ::
          #{name := binary(),
            content_type := binary(),
            length := non_neg_integer(),
            digest := binary(),
            chunked => boolean(),
            chunk_size => pos_integer(),
            chunk_count => pos_integer()}.

change/0

-type change() :: map().

db_config/0

-type db_config() :: #{path => string(), store => module(), atom() => term()}.

db_name/0

-type db_name() :: binary().

db_ref/0

-type db_ref() :: pid() | atom().

doc/0

-type doc() :: #{binary() => term()}.

doc_info/0

-type doc_info() :: #{id := docid(), rev := revid(), deleted := boolean(), revtree := revtree()}.

docid/0

-type docid() :: binary().

endpoint/0

-type endpoint() :: db_name() | {node(), db_name()} | {module(), term()}.

rep_options/0

-type rep_options() ::
          #{continuous => boolean(),
            since => seq_string(),
            filter => fun((doc()) -> boolean()),
            atom() => term()}.

rev_info/0

-type rev_info() ::
          #{id := revid(),
            parent := revid() | undefined,
            deleted := boolean(),
            attachments => #{binary() => att_info()}}.

revid/0

-type revid() :: binary().

revtree/0

-type revtree() :: #{revid() => rev_info()}.

seq/0

-type seq() :: barrel_hlc:timestamp().

seq_string/0

-type seq_string() :: binary().

view_name/0

-type view_name() :: binary().

view_result/0

-type view_result() :: #{key := term(), value := term(), id := docid()}.

Functions

code_change(OldVsn, State, Extra)

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

list_subscriptions(DbName)

-spec list_subscriptions(db_name()) -> [{reference(), binary(), pid()}].

List all subscriptions for a database (for debugging)

match(DbName, Paths)

-spec match(db_name(), [binary()]) -> [pid()].

Find all subscriber PIDs matching the given paths. Paths should be slash-separated binaries like "users/123/name".

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the subscription manager

stop()

-spec stop() -> ok.

Stop the subscription manager

subscribe(DbName, Pattern, Pid)

-spec subscribe(db_name(), binary(), pid()) -> {ok, reference()} | {error, term()}.

Subscribe to document changes matching a pattern Returns a subscription reference that can be used to unsubscribe

terminate(Reason, State)

unsubscribe(SubRef, Pid)

-spec unsubscribe(reference(), pid()) -> ok.

Unsubscribe using the subscription reference