1
1
package io .cloudevents .examples .quarkus .client ;
2
2
3
+ import java .net .URI ;
4
+ import java .util .UUID ;
5
+
6
+ import javax .enterprise .context .ApplicationScoped ;
7
+ import javax .inject .Inject ;
8
+ import javax .ws .rs .core .MediaType ;
9
+
3
10
import com .fasterxml .jackson .databind .ObjectMapper ;
11
+
12
+ import org .eclipse .microprofile .rest .client .inject .RestClient ;
13
+ import org .slf4j .Logger ;
14
+ import org .slf4j .LoggerFactory ;
15
+
4
16
import io .cloudevents .CloudEvent ;
5
17
import io .cloudevents .CloudEventData ;
6
18
import io .cloudevents .core .builder .CloudEventBuilder ;
7
19
import io .cloudevents .core .data .PojoCloudEventData ;
8
20
import io .cloudevents .examples .quarkus .model .User ;
9
- import io .quarkus .runtime .StartupEvent ;
10
- import io .smallrye .mutiny .Multi ;
11
- import org .eclipse .microprofile .rest .client .inject .RestClient ;
12
- import org .slf4j .Logger ;
13
- import org .slf4j .LoggerFactory ;
14
-
15
- import javax .enterprise .context .ApplicationScoped ;
16
- import javax .enterprise .event .Observes ;
17
- import javax .inject .Inject ;
18
- import javax .ws .rs .core .MediaType ;
19
- import java .net .URI ;
20
- import java .time .Duration ;
21
- import java .util .UUID ;
21
+ import io .quarkus .scheduler .Scheduled ;
22
+ import io .smallrye .mutiny .Uni ;
22
23
23
24
@ ApplicationScoped
24
25
public class UserEventsGenerator {
@@ -31,16 +32,14 @@ public class UserEventsGenerator {
31
32
@ Inject
32
33
@ RestClient
33
34
UserClient userClient ;
34
-
35
- public void init (@ Observes StartupEvent startupEvent ) {
36
- Multi .createFrom ().ticks ().every (Duration .ofSeconds (2 ))
37
- .onItem ()
38
- .transform (this ::createEvent )
39
- .subscribe ()
40
- .with (event -> {
41
- LOGGER .info ("try to emit user: {}" , event .getId ());
42
- userClient .emit (event );
43
- });
35
+
36
+ long userCount =0 ;
37
+
38
+ @ Scheduled (every ="2s" )
39
+ public void init () {
40
+ CloudEvent event = createEvent (userCount ++);
41
+ LOGGER .info ("try to emit user: {}" , event .getId ());
42
+ userClient .emit (event );
44
43
}
45
44
46
45
private CloudEvent createEvent (long id ) {
0 commit comments