mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00

Allow access to the Cluster's subscribe(), unsubscribe(), publish(), publish_hrw() and publish_rr() methods by loading only the base/frameworks/cluster/pubsub, rather than everything that __load__.zeek or also main.zeek pulls in. This can be used by other scripts to use these functions without relying or expecting the rest of the cluster framework to be loaded already. Concretely, this is needed to move the Supervisor framework from Broker to Cluster.
49 lines
1.3 KiB
Text
49 lines
1.3 KiB
Text
# A script that can be loaded by other scripts to access the publish subscribe API.
|
|
|
|
@load ./types
|
|
|
|
module Cluster;
|
|
|
|
export {
|
|
## Subscribe to the given topic.
|
|
##
|
|
## topic: The topic to subscribe to.
|
|
##
|
|
## Returns: T on success, else F.
|
|
global subscribe: function(topic: string): bool;
|
|
|
|
## Unsubscribe from the given topic.
|
|
##
|
|
## topic: The topic to unsubscribe from.
|
|
##
|
|
## Returns: T on success, else F.
|
|
global unsubscribe: function(topic: string): bool;
|
|
|
|
## A hook invoked for every :zeek:see:`Cluster::subscribe` call.
|
|
##
|
|
## Breaking from this hook has no effect.
|
|
##
|
|
## topic: The topic string as given to :zeek:see:`Cluster::subscribe`.
|
|
global on_subscribe: hook(topic: string);
|
|
|
|
## A hook invoked for every :zeek:see:`Cluster::subscribe` call.
|
|
##
|
|
## Breaking from this hook has no effect.
|
|
##
|
|
## topic: The topic string as given to :zeek:see:`Cluster::subscribe`.
|
|
global on_unsubscribe: hook(topic: string);
|
|
}
|
|
|
|
# base/bif/cluster.bif.zeek generated from from src/cluster/cluster.bif contains the
|
|
# Cluster::publish(), Cluster::publish_hrw() and Cluster::publish_rr() APIs
|
|
@load base/bif/cluster.bif
|
|
|
|
function subscribe(topic: string): bool
|
|
{
|
|
return Cluster::__subscribe(topic);
|
|
}
|
|
|
|
function unsubscribe(topic: string): bool
|
|
{
|
|
return Cluster::__unsubscribe(topic);
|
|
}
|