Skip to content

ChronoPubSub: simple pub/sub plugin for ChronoLog (#355)#634

Open
iameneko wants to merge 4 commits into
develop-3.xfrom
feature/355-chronopubsub-plugin
Open

ChronoPubSub: simple pub/sub plugin for ChronoLog (#355)#634
iameneko wants to merge 4 commits into
develop-3.xfrom
feature/355-chronopubsub-plugin

Conversation

@iameneko
Copy link
Copy Markdown
Contributor

@iameneko iameneko commented May 5, 2026

Closes #355.

This adds ChronoPubSub, a new client-side plugin that wraps the ChronoLog client with a simple publish/subscribe API. Topics are stories under a single default chronicle: publish(topic, payload) appends a ChronoLog event, and subscribe(topic, callback) / subscribe_from(topic, since_ts, callback) spawn a background polling thread that replays the topic from a per-subscription watermark and dispatches every new event to the user callback in timestamp order. The plugin sits entirely on top of the existing client API, no client changes needed, and the constructor pattern matches chronokvs/chronosql so it can target distributed deployments via a JSON config.

The design intentionally favors extensibility over performance: the polling cadence is per-subscription (default 100 ms), each subscription runs an independent worker, and unsubscribe is safe to call from inside or outside the callback. Cross-process subscribers see published messages only after the publisher calls flush() (or destructs); this matches ChronoLog's read-after-release semantics and is documented in the API. Coverage includes a logger unit test, a config-loading unit test (no live stack required), and a manual integration test that publishes N messages, verifies ordered delivery from the beginning of the topic, exercises live delivery on a second topic, and asserts no callbacks fire after unsubscribe. A publisher/subscriber example pair is shipped under Plugins/chronopubsub/examples/.

Adds a new client-side plugin that wraps the ChronoLog client with a simple
pub/sub interface. Topics map to stories under a default chronicle; publish()
appends an event, subscribe()/subscribe_from() spawn a polling thread that
replays events from a watermark and dispatches each to a user callback.

Mirrors the chronokvs plugin layout: noexcept Create() factories, mapper +
client adapter layers, per-plugin LogLevel and macros. Includes a
publisher/subscriber example pair, GTest unit coverage for logger and config
loading, and a manual integration test that publishes N messages, verifies
ordered delivery, exercises live delivery on a second topic, and asserts no
callbacks fire after unsubscribe.
@iameneko iameneko added Plugins Cross-cutting work on the serving/plugin layer (ChronoKVS, ChronoSQL, ChronoPubSub, etc.) Testing Test infrastructure, coverage, fixtures, end-to-end and unit tests labels May 5, 2026
@iameneko iameneko self-assigned this May 5, 2026
…ation test

The first run failed because the polling subscriber hammered ReplayStory
before keepers had propagated events to a player, getting CL_ERR_QUERY_TIMED_OUT
on every attempt. Mirror chronokvs's pattern: publish, flush, sleep through
the propagation window, then subscribe and let the polling thread deliver.
Also lengthen the test poll interval to 1s and downgrade the mapper's
"replay failed" log to WARNING so retries during propagation don't flood
stderr.
@iameneko iameneko linked an issue May 5, 2026 that may be closed by this pull request
iameneko added 2 commits May 5, 2026 21:28
…le thrash

Subscribing before publishing on the same topic causes the polling
thread's ReleaseStory to invalidate the publisher's cached handle every
cycle; in practice events don't surface in one propagation window.
Mirror Phase 3's publish → flush → wait → subscribe ordering on the
second topic too.
…nd topic

Phase 4 still saw 0/10 deliveries because the Phase 3 subscriber's
1Hz polling loop kept Acquire/ReleaseStory-ing the same chronicle
during the second topic's propagation window, measurably delaying
when its events became readable. Stop sub_id before publishing on
kSecondTopic; verify the re-unsubscribe contract in Phase 5.
@iameneko iameneko marked this pull request as ready for review May 6, 2026 18:31
@iameneko iameneko requested review from fkengun and ibrodkin May 6, 2026 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Plugins Cross-cutting work on the serving/plugin layer (ChronoKVS, ChronoSQL, ChronoPubSub, etc.) Testing Test infrastructure, coverage, fixtures, end-to-end and unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChronoPubSub Plugin

1 participant