Skip to content

Commit

Permalink
broker/cluster: Changes for auto_publish() deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
awelzel committed Dec 6, 2024
1 parent a06a267 commit 2a8c7da
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
26 changes: 16 additions & 10 deletions frameworks/broker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <https://github.com/zeek/zeek/discussions/3637>`_.

.. deprecated:: 7.1

Remote Logging
--------------

Expand Down
9 changes: 0 additions & 9 deletions frameworks/broker/events-connector.zeek
Original file line number Diff line number Diff line change
@@ -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);
}
Expand All @@ -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;
}
9 changes: 0 additions & 9 deletions frameworks/broker/events-listener.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
6 changes: 0 additions & 6 deletions frameworks/cluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a8c7da

Please sign in to comment.