VMWare has launched Spring for Apache Kafka 3.0 and Spring for RabbitMQ 3.0 requiring Java 17 and Spring Framework 6.0. The tasks now help the creation of native GraalVM purposes and remark for timers and tracing by utilizing the Micrometer metrics facade. Each tasks now present a Invoice of Supplies (BOM) within the pom.xml
file to help with dependency administration.
Micrometer is used to instrument JVM code with out vendor lock-in to permit remark for timers and tracing for the KafkaTemplate
, the RabbitTemplate
and listener containers. Micrometer is comparable with SLF4J, a logging facade, however for metrics.
Spring AOT native hints at the moment are out there so as to create native photos for Spring purposes with Spring for Apache Kafka or Spring for RabbitMQ. Examples can be found within the spring-aot-smoke-tests undertaking on GitHub. The EmbeddedKafkaBroker
class from the spring-kafka-test
module isn’t supported in native photos.
Spring for Apache Kafka 3.0 requires Kafka purchasers model 3.3.1 and a minimal dealer (Kafka server) model of two.5 is required when utilizing transactions.
A single international EmbeddedKafkaBroker
might now be used throughout a number of take a look at courses by changing the bootstrap servers property with one thing like:
public ultimate class EmbeddedKafkaContainer {
non-public static EmbeddedKafkaBroker embeddedKafkaBroker =
new EmbeddedKafkaBroker(1, false)
.brokerListProperty("spring.kafka.bootstrap-servers");
non-public static boolean began;
public static EmbeddedKafkaBroker getEmbeddedKafkaBroker() {
if (!began) {
strive {
embeddedKafkaBroker.afterPropertiesSet();
}
catch (Exception exception) {
throw new KafkaException("Error beginning
EmbeddedKafkaBroker", exception);
}
began = true;
}
return embeddedKafkaBroker;
}
non-public EmbeddedKafkaContainer() {
tremendous();
}
}
After configuring the EmbeddedKafkaBroker
, it could be utilized in every take a look at class:
static {
EmbeddedKafkaHolder.getEmbeddedKafkaBroker()
.addTopics("college students", "trainer");
}
non-public static ultimate EmbeddedKafkaBroker dealer =
EmbeddedKafkaContainer.getEmbeddedKafkaBroker();
With the earlier instance, the dealer retains working after finishing the exams which can result in a possible drawback. For instance, when utilizing a Gradle daemon, the destroy()
technique on EmbeddedKafkaBroker
needs to be known as in spite of everything exams are executed.
The GlobalEmbeddedKafkaTestExecutionListener
begins a world EmbeddedKafkaBroker
for the take a look at plan and stops it when the take a look at plan is executed. The listener is disabled by default and could also be enabled by way of the spring.kafka.international.embedded.enabled
property on JUnit Platform 1.8 or newer.
The @RetryableTopic
annotation for non-blocking retries is not experimental. The annotation was additional improved on this launch and will now be used as a meta-annotation on customized annotations. A number of @RetryableTopic
listeners could also be configured on the identical subject in the identical utility context. The container now publishes the ConsumerRetryAuthEvent
and ConsumerRetryAuthSuccessfulEvent
occasions.
The varied ship strategies outlined within the KafkaTemplate
and ReplyingKafkaTemplate
courses now return a CompletableFuture
as an alternative of the deprecated ListenableFuture
.
Spring for RabbitMQ now helps tremendous streams with single lively customers. Tremendous streams are created by binding a number of stream queues to an trade with the argument x-super-stream: true
. The bean of kind SuperStream
can be utilized to create the trade take a look at.trade and two queues or partitions:
@Bean
SuperStream superStream() {
return new SuperStream("take a look at.trade", 2);
}
Listener strategies annotated with the @RabbitListener
annotation might now eat a batch of messages of kind Assortment
or Record
.
The ship strategies of the courses AsyncRabbitTemplate
, RabbitStreamTemplate
and the interface RabbitStreamOperations
now return CompletableFuture
as an alternative of the deprecated ListenableFuture
.
Assist for distant technique invocation (RMI) in Spring for RabbitMQ has been eliminated.
Extra info is offered within the What’s New pages for Kafka and RabbitMQ.