Skip to content

Instantly share code, notes, and snippets.

View danielkec's full-sized avatar
🚀

Daniel Kec danielkec

🚀
View GitHub Profile
@danielkec
danielkec / gist:8a12cc970ec872c3174b4f2b7ce4a7c8
Created June 17, 2020 18:50
SE Messaging with MP config
mp.messaging:
incoming.from-kafka:
connector: helidon-kafka
topic: messaging-test-topic-1
auto.offset.reset: latest
enable.auto.commit: true
outgoing.to-kafka:
connector: helidon-kafka
package io.helidon.reactive.jmh;
import java.util.List;
import java.util.concurrent.Flow;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import io.helidon.common.reactive.BufferedEmittingPublisher;
import io.helidon.common.reactive.Multi;
import io.helidon.common.reactive.OriginThreadPublisher;
Multi.just(1, 2, 3, 4, 5)
.flatMap(i -> Multi.just(i, i))
.limit(4)
.distinct()
.forEach(System.out::println);
> 1
> 2
<dependency>
<groupId>io.helidon.microprofile.reactive-streams</groupId>
<artifactId>helidon-microprofile-reactive-streams</artifactId>
<version>${helidon.version}</version>
</dependency>
@Outgoing("int-channel")
public Publisher<Integer> produceInts() {
return Flowable.just(1, 2, 3);
}
@Incoming("int-channel")
public void consumeInt(Integer value) {
System.out.println("Consuming Integer: " + value);
}
AtomicInteger sum = new AtomicInteger();
Flux<Integer> flux = Flux.just("1", "2", "3", "4", "5")
.map(Integer::parseInt);
ReactiveStreams.fromPublisher(flux)
.limit(3)
.forEach(sum::addAndGet)
.run()
.whenComplete((r, t) -> System.out.println("Sum: " + sum.get()));
AtomicInteger sum = new AtomicInteger();
Flowable<Integer> flowable = Flowable.just("1", "2", "3", "4", "5")
.map(Integer::parseInt);
ReactiveStreams.fromPublisher(flowable)
.limit(3)
.forEach(sum::addAndGet)
.run()
.whenComplete((r, t) -> System.out.println("Sum: " + sum.get()));
AtomicInteger sum = new AtomicInteger();
ReactiveStreams.of("1", "2", "3", "4", "5")
.limit(3)
.map(Integer::parseInt)
.forEach(sum::addAndGet)
.run()
.whenComplete((r, t) -> System.out.println("Sum: " + sum.get()));
> Sum: 6
@Outgoing("test-channel")
public Publisher<Message<String>> produceMessage() {
return ReactiveStreams.of(Message.of("test-data", () -> {
System.out.println("Message acked!");
return CompletableFuture.completedStage(null);
})).buildRs();
}
@Incoming("test-channel")
@Acknowledgment(Acknowledgment.Strategy.POST_PROCESSING)