@runnel/metric-plugin
To verify publisher/subscriber calls, use @runnel/metric-plugin which collects six types of data:
schema
- The schema of the topic.onCreateTopic
: The number of the topic created.lastPayload
: The latest payload to the topic.onPostMessage
: The number of the topic published.onAddEventListener
: The number of the topic subscribed to.onRemoveEventListener
: The number of the topic unsubscribed from.
Usage
import { createPlugin, type Metrics } from "@runnel/metric-plugin";
import { runnel } from "runneljs";
const { register, observer } = createPlugin(deepEqual);
const eventBus = runnel("my-event-bus", deepEqual, validator);
register();
...
// Example with React.useState
const [metrics, setMetrics] = useState<Metrics>();
observer.subscribe(setMetrics);
Find more usage example on the Guides page.
Output Examples
Case 1
topic1
with schema{ "type": "number" }
.- No subscribers.
- One publish event with payload
100
.
{
"topic1": {
"schema": { "type": "number" },
"onCreateTopic": 1,
"lastPayload": 100,
"onPostMessage": 1,
"onAddEventListener": 0,
"onRemoveEventListener": 0
}
}
Case 2
topic2
with schema{ "type": "string" }
.- One subscriber.
- No publish events.