Interface EventLogWriter
-
- All Known Implementing Classes:
EventLogWriterImpl
public interface EventLogWriterThe main user interface for this library. Autowire an instance of this interface into your service, and call one of the methods whenever you want to send an event.All the methods are supposed to be called inside the same database transaction which also contains the corresponding changes to your business objects. This way it is made sure that the events are persisted if and only if the containing transaction is successful, sidestepping the distributed transaction problem.
The library will later try to submit all those persisted events to Nakadi.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidfireBusinessEvent(String eventType, Object payload)Fires a business event, i.e. an event communicating the fact that some business process step happened.voidfireBusinessEvents(String eventType, Collection<Object> payloads)Fires business events, seefireBusinessEventfor more detailsvoidfireCreateEvent(String eventType, String dataType, Object data)Fires a data change event about a creation of some resource (object).voidfireCreateEvents(String eventType, String dataType, Collection<?> data)Fires data change events about the creation of some resources (objects), seefireCreateEventfor more details.voidfireDeleteEvent(String eventType, String dataType, Object data)Fires a data change event about the deletion of some resource (object).voidfireDeleteEvents(String eventType, String dataType, Collection<?> data)Fires data change events about the deletion of some resources (objects), seefireDeleteEventfor more details.voidfireSnapshotEvent(String eventType, String dataType, Object data)Fires a data change event with a snapshot of some resource (object).voidfireSnapshotEvents(String eventType, String dataType, Collection<?> data)Fires data change events, seefireSnapshotEventfor more details.voidfireUpdateEvent(String eventType, String dataType, Object data)Fires a data change event about an update of some resource (object).voidfireUpdateEvents(String eventType, String dataType, Collection<?> data)Fires data change events about the update of some resources (objects), seefireUpdateEventfor more details.<X> voidregisterCompactionKeyExtractor(String eventType, Class<X> dataType, CompactionKeyExtractor<X> extractor)Registers a function for extracting compaction keys for events sent in the future.
-
-
-
Method Detail
-
registerCompactionKeyExtractor
<X> void registerCompactionKeyExtractor(String eventType, Class<X> dataType, CompactionKeyExtractor<X> extractor)
Registers a function for extracting compaction keys for events sent in the future.When an event for this event type is sent out, and its `data` (or `payload`) object matches the type, the extractor is used to set the
partition_compaction_keyin the event to be sent out. For all other objects (or if the extractor returns null), no compaction key is set.(If multiple extractors are registered for the same event type, their data type is checked in reverse order of registering, until a fitting one is found. The first with matching dataType is used.)
- Note
- Nakadi-Producer does not guarantee event ordering, which is fundamentally incompatible with Nakadi's log-compaction mechanism, as Nakadi will always keep just the last submitted event for the same compaction key, which might not be the last produced one. Still, in some special cases (e.g. when there is normally a long time between production of events with the same compaction key, so all events will be sent out before the next group) it is possible without problems (and these are also cases where the compaction is most useful). This feature is meant just for these special cases.
- Parameters:
eventType- the event type for which this is used.dataType- the Java type of the objects for which the extractor is used.extractor- a function which will extract the compaction key from an object.
-
fireCreateEvent
void fireCreateEvent(String eventType, String dataType, Object data)
Fires a data change event about a creation of some resource (object).- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi event.data- some POJO that can be serialized into JSON (required parameter). This is meant to be a representation of the resource which was created. It will be used as content of thedatafield of the Nakadi event.
-
fireCreateEvents
void fireCreateEvents(String eventType, String dataType, Collection<?> data)
Fires data change events about the creation of some resources (objects), seefireCreateEventfor more details.- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi eventdata- some POJOs that can be serialized into JSON (required parameter). This is meant to be a representation of the current state of the resource. It will be used as content of thedatafield of the Nakadi event.
-
fireUpdateEvent
void fireUpdateEvent(String eventType, String dataType, Object data)
Fires a data change event about an update of some resource (object).- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi event.data- some POJO that can be serialized into JSON (required parameter). This is meant to be a representation of the new state of the resource which was updated. It will be used as content of thedatafield of the Nakadi event.
-
fireUpdateEvents
void fireUpdateEvents(String eventType, String dataType, Collection<?> data)
Fires data change events about the update of some resources (objects), seefireUpdateEventfor more details.- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi eventdata- some POJOs that can be serialized into JSON (required parameter). This is meant to be a representation of the current state of the resource. It will be used as content of thedatafield of the Nakadi event.
-
fireDeleteEvent
void fireDeleteEvent(String eventType, String dataType, Object data)
Fires a data change event about the deletion of some resource (object).- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi event.data- some POJO that can be serialized into JSON (required parameter). This is meant to be a representation of the last state (before the deletion) of the resource which was deleted. It will be used as content of thedatafield of the Nakadi event.
-
fireDeleteEvents
void fireDeleteEvents(String eventType, String dataType, Collection<?> data)
Fires data change events about the deletion of some resources (objects), seefireDeleteEventfor more details.- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi eventdata- some POJOs that can be serialized into JSON (required parameter). This is meant to be a representation of the current state of the resource. It will be used as content of thedatafield of the Nakadi event.
-
fireSnapshotEvent
void fireSnapshotEvent(String eventType, String dataType, Object data)
Fires a data change event with a snapshot of some resource (object).This notifies your consumers about the current state of a resource, even if nothing changed. Typical use cases include initial replication to new consumers or hotfixes of data inconsistencies between producer and consumer.
Normally applications don't have to call this themselves, instead they should implement the
SnapshotEventGeneratorinterface to add support for snapshot creation via the actuator endpoint.- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi event.data- some POJO that can be serialized into JSON (required parameter). This is meant to be a representation of the current state of the resource. It will be used as content of thedatafield of the Nakadi event.
-
fireSnapshotEvents
void fireSnapshotEvents(String eventType, String dataType, Collection<?> data)
Fires data change events, seefireSnapshotEventfor more details.- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.dataType- the content of thedata_typefield of the Nakadi eventdata- some POJOs that can be serialized into JSON (required parameter). This is meant to be a representation of the current state of the resource. It will be used as content of thedatafield of the Nakadi event.
-
fireBusinessEvent
void fireBusinessEvent(String eventType, Object payload)
Fires a business event, i.e. an event communicating the fact that some business process step happened. The payload object will be used as the main event content (just metadata will be added). Same as for data change events, you should call this method in the same transaction as you are storing related changes into your database.- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.payload- some POJO that can be serialized into JSON (required parameter)
-
fireBusinessEvents
void fireBusinessEvents(String eventType, Collection<Object> payloads)
Fires business events, seefireBusinessEventfor more details- Parameters:
eventType- the Nakadi event type of the event. This is roughly equivalent to an event channel or topic.payloads- some POJOs that can be serialized into JSON (required parameter)
-
-