From 2a8c7dad67c72ba181e2a56ee468f5445b8c478c Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Mon, 18 Nov 2024 14:23:09 +0100 Subject: [PATCH] broker/cluster: Changes for auto_publish() deprecation --- frameworks/broker.rst | 26 +++++++++++++++---------- frameworks/broker/events-connector.zeek | 9 --------- frameworks/broker/events-listener.zeek | 9 --------- frameworks/cluster.rst | 6 ------ 4 files changed, 16 insertions(+), 34 deletions(-) diff --git a/frameworks/broker.rst b/frameworks/broker.rst index 78c2ce9b5..3d102d171 100644 --- a/frameworks/broker.rst +++ b/frameworks/broker.rst @@ -276,19 +276,11 @@ define any event handlers for events that peers will send. :linenos: :tab-width: 4 -There are two different ways to send events. - -The first is to call the :zeek:see:`Broker::publish` function which you can +To send an event, call the :zeek:see:`Broker::publish` function which you can supply directly with the event and its arguments or give it the return value of :zeek:see:`Broker::make_event` in case you need to send the same event/args multiple times. When publishing events like this, local event handlers for -the event are not called. - -The second option is to call the :zeek:see:`Broker::auto_publish` function where -you specify a particular event that will be automatically sent to peers -whenever the event is called locally via the normal event invocation syntax. -When auto-publishing events, local event handlers for the event are called -in addition to sending the event to any subscribed peers. +the event are not called, even if a matching subscription exists. .. literalinclude:: broker/events-connector.zeek :caption: events-connector.zeek @@ -301,6 +293,20 @@ to the ``zeek/events`` topic prefix you would receive events that are published to topic names ``zeek/events/foo`` and ``zeek/events/bar`` but not ``zeek/misc``. + +.. note:: + + In prior Zeek versions, :zeek:see:`Broker::auto_publish` was available to + automatically send events to peers whenever the events were called locally via + the normal event invocation syntax. When auto-publishing events, local + event handlers for the event were called in addition to sending the + event to any subscribed peers. + + :zeek:see:`Broker::auto_publish` has been deprecated due to its + `implicit nature `_. + + .. deprecated:: 7.1 + Remote Logging -------------- diff --git a/frameworks/broker/events-connector.zeek b/frameworks/broker/events-connector.zeek index 28789f06d..fb4bec92e 100644 --- a/frameworks/broker/events-connector.zeek +++ b/frameworks/broker/events-connector.zeek @@ -1,20 +1,16 @@ redef exit_only_after_terminate = T; global my_event: event(msg: string, c: count); -global my_auto_event: event(msg: string, c: count); event zeek_init() { Broker::peer("127.0.0.1"); - Broker::auto_publish("zeek/event/my_auto_event", my_auto_event); } event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) { print "peer added", endpoint; Broker::publish("zeek/event/my_event", my_event, "hi", 0); - event my_auto_event("stuff", 88); Broker::publish("zeek/event/my_event", my_event, "...", 1); - event my_auto_event("more stuff", 51); local e = Broker::make_event(my_event, "bye", 2); Broker::publish("zeek/event/my_event", e); } @@ -28,8 +24,3 @@ event my_event(msg: string, c: count) { print "got my_event", msg, c; } - -event my_auto_event(msg: string, c: count) - { - print "got my_auto_event", msg, c; - } diff --git a/frameworks/broker/events-listener.zeek b/frameworks/broker/events-listener.zeek index 1965ada5a..374dc5db1 100644 --- a/frameworks/broker/events-listener.zeek +++ b/frameworks/broker/events-listener.zeek @@ -22,12 +22,3 @@ event my_event(msg: string, c: count) if ( msg_count == 5 ) terminate(); } - -event my_auto_event(msg: string, c: count) - { - ++msg_count; - print "got my_auto_event", msg, c; - - if ( msg_count == 5 ) - terminate(); - } diff --git a/frameworks/cluster.rst b/frameworks/cluster.rst index fe5101f29..a1846e112 100644 --- a/frameworks/cluster.rst +++ b/frameworks/cluster.rst @@ -334,12 +334,6 @@ function to publish events, including: - Standard function to send an event to all nodes subscribed to a given topic - * - :zeek:see:`Broker::auto_publish` - - Automatically send an otherwise generated Zeek event to any interested - peers whenever it is locally dispatched. - - Avoid, since it is somewhat “magical”, unless you’ve got code - compartmentalization running with ``@ifdef`` directives. - * - :zeek:see:`Cluster::publish_hrw` - Publishes an event to a node within a pool according to Highest Random Weight (HRW) hashing strategy; see details below