Skip to content

csapi-mqtt: Batch Resource Events for observations - #266

Merged
alexrobin merged 1 commit into
masterfrom
feature/cs-api-mqtt/258-batch-events
Nov 12, 2026
Merged

alexrobin merged 1 commit into
masterfrom
feature/cs-api-mqtt/258-batch-events

Conversation

@tipatterson-dev

@tipatterson-dev tipatterson-dev commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Publishes CS API Part 3 Batch Resource Events for the observations of each datastream (/req/resource-events/batch-events, /req/mqtt/batch-resource-events). A datastream can create many observations each second, so the service sends one event with the number of new observations in each time window, not one event for each observation.

Closes #258. Part of #249.

Stacked on #264 (Resource Events, #254) (base feature/cs-api-mqtt/254-resource-events). Merge #261, #263 and #264 first.

Changes

  • TopicMapper accepts the Batch Resource Event topic (no :data): {nodeId}/{systemPath}/datastreams/{id}/observations.
  • New BatchWindow: counts the observations of one datastream and publishes at most one batch in each window.
    • After a quiet window, the first batch is published at once. The next ones are published at the end of the window.
    • A window with no new observations publishes nothing.
  • New BatchEventPublisher:
    • Listens to the data channel of each datastream in the hub database, and of each datastream created later (system registry events).
    • type is org.ogc.api.csapi.observation.create. source is the API root. subject is the canonical observations URL ({apiRoot}/datastreams/{id}/observations) and resourceparent is the canonical datastream URL. Each event has a new id.
    • data is {"timerange": [first, last], "count": n}, with datacontenttype application/json.
    • Stops listening, and drops pending counts, when a datastream or its system is removed, and when the service stops.
  • New config setting batchEventWindowMs (default 1000). 0 publishes one event each time a datastream gets observations. A negative value is rejected.
  • CsApiMqttConnector (no code change): the batch topic uses the event topic checks of csapi-mqtt: Resource Events for systems, datastreams and control streams #264. A subscriber must be able to read the datastream, and client publications are rejected as not authorized.
  • AsyncAPI description: the observationBatchEvents channel, a batch CloudEvents schema with data, and the configured window in the channel description.
  • README: Batch Resource Events section, the window setting, status, and known limits.

Not included

  • Batch events for commands, command status, command results and system events. Part 3 allows a server to publish batch events for some collections, if the service description lists them.
  • Events for one observation (.../observations/{id}) are rejected. They need osh-core changes first.
  • Wildcard subscriptions (consys-mqtt: accept wildcard subscriptions #255).

Known limits

  • Events are published for each datastream that gets observations, also when no client subscribes.
  • Observations not yet in an event when the service stops are not published.

Testing

  • TestBatchWindow: first event at once, events after a quiet window, one flush at the end of the window, second window cycle, quiet window, time range order, rejected schedule, close, zero window.
  • TestBatchEventPublisher: topic and CloudEvent JSON, a new id for each event, unknown datastream, datastream and system removal, stop. testEventsFromEventBus uses a real osh-core EventBus, so that the subscription delivers events.
  • TestTopicMapper: batch topics for top-level systems and nested subsystems, and rejected topics.
  • TestAsyncApiHandler: batch channel, event type and the configured window.
  • On a test node:
    • 1 Hz drivers (counter, fake weather): one event each second, count 1, with the correct subject, resourceparent and timerange
    • datastream created over HTTP after start: 50 observations in 0.4 s gave count 1 at once, then count 49 at the end of the window; after a quiet gap, 20 observations gave 1, then 19
    • a datastream with no new observations: no events
    • subscribe to an unknown datastream or to .../observations/{id}: rejected; client publish to the batch topic: not authorized

Stack

  1. csapi-mqtt: Part 3 topic scheme (new module, 0.1.0) #261 Part 3 topic scheme
  2. csapi-mqtt: AsyncAPI service description #263 AsyncAPI service description
  3. csapi-mqtt: Resource Events for systems, datastreams and control streams #264 Resource Events
  4. This PR

@tipatterson-dev tipatterson-dev self-assigned this Nov 6, 2026
@tipatterson-dev tipatterson-dev changed the title consys-mqtt: Batch Resource Events for observations csapi-mqtt: Batch Resource Events for observations Nov 9, 2026
@tipatterson-dev
tipatterson-dev force-pushed the feature/cs-api-mqtt/258-batch-events branch from 713c445 to d1a9f9d Compare November 12, 2026 02:02
@alexrobin
alexrobin force-pushed the feature/cs-api-mqtt/258-batch-events branch from d1a9f9d to f9f58e5 Compare November 12, 2026 07:27
Base automatically changed from feature/cs-api-mqtt/254-resource-events to master November 12, 2026 07:37
@alexrobin
alexrobin force-pushed the feature/cs-api-mqtt/258-batch-events branch from f9f58e5 to 1d441b5 Compare November 12, 2026 07:37
@alexrobin
alexrobin self-requested a review November 12, 2026 07:37
@alexrobin
alexrobin merged commit 5ca1a3a into master Nov 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

consys-mqtt: publish Batch Resource Events for observations

2 participants