Search code examples
spring-cloudspring-kafkadead-letterspring-cloud-stream-binder-kafka

How to Properly Unit Test Dlq within Spring Cloud Stream


There's some native configurations like enableDlq within spring cloud stream kafka binder, but there's not any example's that i've found on how to properly unit test if the enableDlq is working properly. Are there any examples out there of how to properly implement this type of test?


Solution

  • There are a bunch of tests in the binder project itself:

    https://github.com/spring-cloud/spring-cloud-stream-binder-kafka/blob/33aa926940ffdbe9d0847b4eab020ccbadfab062/spring-cloud-stream-binder-kafka/src/test/java/org/springframework/cloud/stream/binder/kafka/KafkaBinderTests.java#L941-L1193

    The general technique there is to bind to the dlq with a separate binding, but you can equally well just define a KafkaConsumer to consume from it and verify that it received the message you expected.