-
Notifications
You must be signed in to change notification settings - Fork 8
/
EventLogWriter.java
235 lines (222 loc) · 9.02 KB
/
EventLogWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package org.zalando.nakadiproducer.eventlog;
import java.util.Collection;
import javax.transaction.Transactional;
import org.zalando.nakadiproducer.snapshots.SnapshotEventGenerator;
/**
* The 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.
* <p>
* 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.
* </p>
* <p>
* The library will later try to submit all those persisted events to Nakadi.
* </p>
*/
public interface EventLogWriter {
/**
* Fires a data change event about a <b>creation</b> of some resource
* (object).
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event.
*
* @param 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 the
* {@code data} field of the Nakadi event.
*/
@Transactional
void fireCreateEvent(String eventType, String dataType, Object data);
/**
* Fires data change events about the creation of some resources (objects), see
* {@link #fireCreateEvent(String, String, Object) fireCreateEvent} for more details.
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event
*
* @param data
* 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
* the {@code data} field of the Nakadi event.
*/
@Transactional
void fireCreateEvents(String eventType, String dataType, Collection<?> data);
/**
* Fires a data change event about an update of some resource (object).
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event.
*
* @param 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 the {@code data} field of the Nakadi event.
*/
@Transactional
void fireUpdateEvent(String eventType, String dataType, Object data);
/**
* Fires data change events about the update of some resources (objects), see
* {@link #fireUpdateEvent(String, String, Object) fireUpdateEvent} for more details.
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event
*
* @param data
* 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
* the {@code data} field of the Nakadi event.
*/
@Transactional
void fireUpdateEvents(String eventType, String dataType, Collection<?> data);
/**
* Fires a data change event about the deletion of some resource (object).
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event.
*
* @param 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 the {@code data} field of the
* Nakadi event.
*/
@Transactional
void fireDeleteEvent(String eventType, String dataType, Object data);
/**
* Fires data change events about the deletion of some resources (objects), see
* {@link #fireDeleteEvent(String, String, Object) fireDeleteEvent} for more details.
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event
*
* @param data
* 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
* the {@code data} field of the Nakadi event.
*/
@Transactional
void fireDeleteEvents(String eventType, String dataType, Collection<?> data);
/**
* Fires a data change event with a snapshot of some resource (object).
* <p>
* 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.
* </p>
* <p>
* Normally applications don't have to call this themselves, instead they
* should implement the
* {@link SnapshotEventGenerator}
* interface to add support for snapshot creation via the actuator endpoint.
* </p>
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event.
*
* @param 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
* the {@code data} field of the Nakadi event.
*/
@Transactional
void fireSnapshotEvent(String eventType, String dataType, Object data);
/**
* Fires data change events, see {@link #fireSnapshotEvent(String, String, Object)
* fireSnapshotEvent} for more details.
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param dataType
* the content of the {@code data_type} field of the Nakadi
* event
*
* @param data
* 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
* the {@code data} field of the Nakadi event.
*/
@Transactional
void fireSnapshotEvents(String eventType, String dataType, Collection<?> data);
/**
* 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.
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param payload
* some POJO that can be serialized into JSON (required
* parameter)
*/
@Transactional
void fireBusinessEvent(String eventType, Object payload);
/**
* Fires business events, see {@link #fireBusinessEvent(String, Object) fireBusinessEvent} for
* more details
*
* @param eventType
* the Nakadi event type of the event. This is roughly equivalent
* to an event channel or topic.
*
* @param payloads
* some POJOs that can be serialized into JSON (required
* parameter)
*/
@Transactional
void fireBusinessEvents(String eventType, Collection<?> payloads);
}