use of com.rabbitmq.stream.Producer in project rabbitmq-stream-java-client by rabbitmq.
the class SuperStreamProducerTest method allMessagesSentToSuperStreamWithHashRoutingShouldBeThenConsumed.
@Test
void allMessagesSentToSuperStreamWithHashRoutingShouldBeThenConsumed() throws Exception {
int messageCount = 10_000;
declareSuperStreamTopology(connection, superStream, partitions);
Producer producer = environment.producerBuilder().stream(superStream).routing(message -> message.getProperties().getMessageIdAsString()).producerBuilder().build();
CountDownLatch publishLatch = new CountDownLatch(messageCount);
IntStream.range(0, messageCount).forEach(i -> producer.send(producer.messageBuilder().properties().messageId(UUID.randomUUID().toString()).messageBuilder().build(), confirmationStatus -> publishLatch.countDown()));
assertThat(latchAssert(publishLatch)).completes(5);
Map<String, AtomicLong> counts = new ConcurrentHashMap<>();
AtomicLong totalCount = new AtomicLong(0);
IntStream.range(0, partitions).forEach(i -> {
String stream = superStream + "-" + i;
AtomicLong streamCount = new AtomicLong(0);
counts.put(stream, streamCount);
environment.consumerBuilder().stream(stream).offset(OffsetSpecification.first()).messageHandler((context, message) -> {
streamCount.incrementAndGet();
totalCount.incrementAndGet();
}).build();
});
waitAtMost(10, () -> totalCount.get() == messageCount);
assertThat(counts.values().stream().map(AtomicLong::get)).hasSize(partitions).doesNotContain(0L);
assertThat(counts.values().stream().map(AtomicLong::get).reduce(0L, Long::sum)).isEqualTo(messageCount);
}
Aggregations