Signed-off-by: Thomas Qvarnström <tqvarnst@redhat.com>
This commit is contained in:
parent
d49ff9f69d
commit
12eee4da6e
|
@ -10,10 +10,10 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cloudevents-restful-ws-quarkus-example</artifactId>
|
||||
<properties>
|
||||
<quarkus-plugin.version>1.7.1.Final</quarkus-plugin.version>
|
||||
<quarkus-plugin.version>1.10.3.Final</quarkus-plugin.version>
|
||||
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
|
||||
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
|
||||
<quarkus.platform.version>1.7.1.Final</quarkus.platform.version>
|
||||
<quarkus.platform.version>1.10.3.Final</quarkus.platform.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
@ -35,6 +35,10 @@
|
|||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-scheduler</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-api</artifactId>
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
package io.cloudevents.examples.quarkus.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.core.builder.CloudEventBuilder;
|
||||
import io.cloudevents.core.data.PojoCloudEventData;
|
||||
import io.cloudevents.examples.quarkus.model.User;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import io.smallrye.mutiny.Multi;
|
||||
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.event.Observes;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.net.URI;
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
import io.quarkus.scheduler.Scheduled;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
@ApplicationScoped
|
||||
public class UserEventsGenerator {
|
||||
|
@ -31,16 +32,14 @@ public class UserEventsGenerator {
|
|||
@Inject
|
||||
@RestClient
|
||||
UserClient userClient;
|
||||
|
||||
long userCount=0;
|
||||
|
||||
public void init(@Observes StartupEvent startupEvent) {
|
||||
Multi.createFrom().ticks().every(Duration.ofSeconds(2))
|
||||
.onItem()
|
||||
.transform(this::createEvent)
|
||||
.subscribe()
|
||||
.with(event -> {
|
||||
LOGGER.info("try to emit user: {}", event.getId());
|
||||
userClient.emit(event);
|
||||
});
|
||||
@Scheduled(every="2s")
|
||||
public void init() {
|
||||
CloudEvent event = createEvent(userCount++);
|
||||
LOGGER.info("try to emit user: {}", event.getId());
|
||||
userClient.emit(event);
|
||||
}
|
||||
|
||||
private CloudEvent createEvent(long id) {
|
||||
|
|
|
@ -3,4 +3,5 @@
|
|||
|
||||
## The Rest client will send events to the local UserResource
|
||||
io.cloudevents.examples.quarkus.client.UserClient/mp-rest/url=http://localhost:8080
|
||||
%test.io.cloudevents.examples.quarkus.client.UserClient/mp-rest/url=http://localhost:8081
|
||||
io.cloudevents.examples.quarkus.client.UserClient/mp-rest/scope=javax.inject.Singleton
|
||||
|
|
Loading…
Reference in New Issue