BoundedQueueSource API
This commit is contained in:
parent
708f8b870c
commit
779161d556
11 changed files with 358 additions and 115 deletions
|
|
@ -765,6 +765,44 @@ public class IntegrationDocTest extends AbstractJavaTest {
|
|||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illustrateSynchronousSourceQueue() throws Exception {
|
||||
new TestKit(system) {
|
||||
{
|
||||
// #source-queue-synchronous
|
||||
int bufferSize = 10;
|
||||
int elementsToProcess = 5;
|
||||
|
||||
BoundedSourceQueue<Integer> sourceQueue =
|
||||
Source.<Integer>queue(bufferSize)
|
||||
.throttle(elementsToProcess, Duration.ofSeconds(3))
|
||||
.map(x -> x * x)
|
||||
.to(Sink.foreach(x -> System.out.println("got: " + x)))
|
||||
.run(system);
|
||||
|
||||
List<Integer> fastElements = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
||||
|
||||
fastElements.stream()
|
||||
.forEach(
|
||||
x -> {
|
||||
QueueOfferResult result = sourceQueue.offer(x);
|
||||
if (result == QueueOfferResult.enqueued()) {
|
||||
System.out.println("enqueued " + x);
|
||||
} else if (result == QueueOfferResult.dropped()) {
|
||||
System.out.println("dropped " + x);
|
||||
} else if (result instanceof QueueOfferResult.Failure) {
|
||||
QueueOfferResult.Failure failure = (QueueOfferResult.Failure) result;
|
||||
System.out.println("Offer failed " + failure.cause().getMessage());
|
||||
} else if (result instanceof QueueOfferResult.QueueClosed$) {
|
||||
System.out.println("Bounded Source Queue closed");
|
||||
}
|
||||
});
|
||||
|
||||
// #source-queue-synchronous
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illustrateSourceActorRef() throws Exception {
|
||||
new TestKit(system) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue