Guk
Guk

Reputation: 71

How to test DLQ on Spring Cloud Stream?

I'm struggling to guarantee that DLQ is working properly on test code. Here is my properties file.

spring.application.name=parsing-processor
spring.cloud.function.definition=parsing

spring.cloud.stream.function.bindings.parsing-in-0=input
spring.cloud.stream.function.bindings.parsing-out-0=output

spring.cloud.stream.bindings.input.group=inflow
spring.cloud.stream.bindings.input.consumer.max-attempts=1

spring.cloud.stream.kafka.bindings.input.consumer.enable-dlq=true
spring.cloud.stream.kafka.bindings.input.consumer.dlq-name=inflow-parsingdlq

And this is my test code.

@SpringBootTest (
    properties = [
        "spring.cloud.stream.kafka.binder.configuration.cache.max.bytes.buffering=0",
    ]
)
class DlqTest @Autowired constructor(
    private val inputDestination: InputDestination,
    private val outputDestination: OutputDestination,
    private val converter: CompositeMessageConverter,
) {

    @Test
    fun test() {
        val rawString = readFileAsString("failing_rawstring.json")

        val inflowMessage = InflowMessage(rawString)
        // When
        val headers = MessageHeaders(mapOf("contentType" to "application/json"))
        val message = converter.toMessage(inflowMessage, headers)
        inputDestination.send(message, "input")

        val payload = outputDestination.receive(2000, "inflow-parsingdlq")

        // Then
        assertThat(payload).isNotNull()
    }
}

The payload is always null. How can I fix it? I used EmbeddedKafka before, but it failed too. Is there a example for it?

Upvotes: 0

Views: 33

Answers (0)

Related Questions