Deactivate Kafka message sending and receiving for testing in Spring boot project - spring-boot

I want to do some integration testing in a spring boot project, where kafka is used.
For these tests I don't want any messages to be sent or received from kafka. Is there a way to configure this?

Kafka test containers help me to do integration tests with kafka
. May be it'll help you.

Related

Spring Cloud Contract & Test Container

I am using Spring Cloud Contract, now I am making an integration test for event driven microservices.
Can i combine both Spring Cloud Contract (messaging) with Kafka container running on TestContainer? I want to use the StubTrigger of course but it should fetch the message also from my Kafka topic. Any suggestion? Does it even make sense? I think i am mixing the concepts.
Yes you can. You can check out the examples with kafka and testcontainers here https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/main/consumer_kafka_middleware and here https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/main/producer_kafka_middleware

Hook in Spring Boot to plug in own RabbitMQ client?

I'm thinking of developing a simulation of RabbitMQ that can be used in unit tests where it is not possible to start up an entire RabbitMQ server or not possible to connect to one. This RabbitMQ simulation would obviously have the same API as the RabbitMQ Java client. Question is now how to plug in this API of the RabbitMQ simulation into Spring Boot instead of the original one from RabbitMQ. Is there some hook in Spring Boot so that this could be done?
It's quite difficult to simulate RabbitMQ.
Some people have has some success using an embedded Apache QPID server running amqp 0.9.1.
However, it doesn't support any RabbitMQ extensions, if you are using those.
You'd be better off using something like TestContainers.
https://www.testcontainers.org/modules/rabbitmq/

Which is the better combination? spring boot with kafka

i am designing realtime kafka consuming job, and considering between spring boot batch and spring boot.
kafka version : 2.11-1.1.1
jdk : 1.8
which is better?
spring boot batch + kafka
spring boot + kafka
and please tell me why :)
If you are thinking to create job and manage through spring cloud data flow further, go with the #1 and if you use case is to just keep consuming the kafka message when recieved to kafka topic, use spring boot and spring kafka. It totally depend on your use case.

Spring Integration - ActiveMQ to Kafka

I am currently trying to write an adapter which will consume messages from ActiveMQ and publish it to Kafka.
I am thinking of using spring integration to integrate these two messaging systems.
My problem is that my application will not maintain registry of the Models using which many applications will publish the records to activeMQ. I want to receive these javax jms message and want to perform some transformation like adding jmscorrelationId into kafka message.
ALso, another requirement is to send acknowledgement to active mq only when kafka send/publish is successfull.
Can ack be send back to activemq using spring integration?
Will spring integration be a good option?
Kindly note my tech architect is not in favor of using Camel/Mule. Also, he does not want to use Kafka Connect as i was planning to use Kafka connect source.
Please suggest.
The Spring Integration Kafka extension project has a sync mode for publishing, which will block the thread until Kafka confirms delivery (or throw an exception on a failure).
The JMS inbound gateway can be used to return a reply to a JMS queue.
You can add transformers (or whatever) in the flow to modify the message.

Spring Cloud Contract and plain Spring AMQP

We are using plain Spring AMQP in our spring boot projects.
We want to make sure that our message consumers can test against real messages and avoid to test against static test messages.
Thus our producers could generate message snippets in a test phase that can be picked up by the consumer test to make sure it tests against the latest message version and see if changes in the producer break the consumer.
It seems like Spring Cloud Contract does exactly that. So is there a way to integrate spring cloud contract with spring amqp? Any hints in which direction to go would be highly appreciated.
Actually we don't support it out of the box but you can set it up yourself. In the autogenerated tests we're using an interface to receive and send messages so
you could implement your own class that uses spring-amqp. The same goes for the consumer side (the stub runner). What you would need to do is to implement and register a bean of
org.springframework.cloud.contract.verifier.messaging.MessageVerifier type for both producer and consumer. This should work cause what we're doing in the autogenerated tests is that we #Inject MessageVerifier
so if you register your own bean it will work.
UPDATE:
As #Mathias has mentioned it, the AMQP support is already there in Spring Cloud Contract https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_stub_runner_spring_amqp

Resources