Claus Radloff
Claus Radloff

Reputation: 363

How to disable Kafka in Quarkus test?

My application uses Kafka and Hibernate. For Kafka a running docker image is required. If I run a Quarkus test for Hibernate, the test fails if Kafka is not running. In my IDE this is not a problem, but in Jenkins there is no Kafka server available and the test fails because it cannot resolve the Kafka server.

Is it possible to disable Kafka in Quarkus tests?

Upvotes: 3

Views: 2232

Answers (1)

Denis.Kipchakbaev
Denis.Kipchakbaev

Reputation: 1070

You could make use of Microprofile's Emitter for sending messages to Kafka channel:

@Inject 
@Channel("hello")
Emitter<String> emitter;

By default, in case when there is no Kafka behind that emitter, it will create an in-memory message bus. So the docker image for Kafka would not be required.

Another solution would be to use KafkaContainer from TestContainers to create a throwaway Kafka container for each test run.

You could check both examples in Alex Soto's repository.
Look at CheckoutProcess class and corresponding component test and integration test.

Upvotes: 3

Related Questions