Search code examples
springspring-bootspring-cloudspring-cloud-contract

Spring Cloud Contract - Mixing http and messaging


I want to start using SCC but I can't find how to implement one particular case we have. Service receives input in form of Kafka message and needs to call external rest api with payload based from that input message. And it also goes other way around, when we receive rest call, result should be Kafka message. Is there any support in SCC for this ?


Solution

  • Of course. Your application is a comsumer and a producer of a message. Also it has a controller and consumes an http controller from another service. You have the following contracts to create.

    Contract 1 - on the producer of the kafka message to verify whether it can send a message to the broker (let's call it service A). Service B will reuse the stub of that message to check if it can consume the message from kafka.

    Contract 2 - on the producer of the http endpoint that will be called when a message was received (service C).

    Contract 3 - on the producer of the http endpoint that will be called "the other way round" (service B)

    Contract 4 - producer of the message to kafka "the other way round".

    Important thing to remember is that you test those in isolation. That means that if you get a message from kafka and then you want to make an http call them you mock everything that your message listener calls. Same thing for the http based communication. If your controller makes use of an application service you'll mock it out.