Event Collector Plugin
The Event Collector Plugin is designed to gather various events generated during the execution of BifroMQ. By filtering through event types, you can focus on the events that matter to you, enabling the implementation of various business logic such as usage statistics, monitoring, alerts, etc. The Plugin's interface is defined in the following Maven module:
<dependency>
<groupId>com.baidu.bifromq</groupId>
<artifactId>bifromq-plugin-event-collector</artifactId>
<version>X.Y.Z</version> <!--replace X.Y.Z with the latest version number-->
</dependency>
Event Types
The types of event objects generated by BifroMQ during runtime all inherit from the Event class. Each specific event class corresponds to an EventType enum, which can be accessed through the type()
method on the object, facilitating the implementation of event filtering logic. The hlc()
method allows for the retrieval of an event object's timestamp. BifroMQ's timestamps are partially ordered, reflecting the sequence in which events occur. This is particularly useful for handling events in BifroMQ during distributed deployment.
Report Method
When an event is generated, BifroMQ invokes the Plugin’s report()
method. The method signature is as follows:
public void report(Event<?> event);
This method is called on BifroMQ's worker thread. With the increase in load, a large number of events will be generated. To avoid the creation of a multitude of event objects and excessive memory overhead, the event object passed into this method will be reused after the method returns. Therefore, when implementing the Event Collector Plugin, it's important to consider the following:
- Avoid incorporating heavy business logic within the report method to ensure that it returns quickly; otherwise, it may adversely affect BifroMQ's performance.
- The ownership of the passed-in event does not get transferred. If the business logic is asynchronous and you need to access the content of the event after the report method returns, you should create a shallow copy of the object using the
clone()
method before returning.
Please note that efficient handling within the report()
method is critical for maintaining the performance and scalability of the BifroMQ system.