java

Spring Cloud Contract

Consumer-Driven Contracts are an approach to ensure service communication compatibility, in which the Consumer and Provider make an agreement about the format of the data they transfer between each other. This agreement forms the so-called Contract.

Normally, the format of the contract is defined by the Consumer and shared with the corresponding Provider. Afterwards, tests are being implemented in order to verify that the contract is being kept, called Contract Tests.

It is a project of spring-cloud that helps end-users in successfully implementing the Consumer Driven Contracts (CDC) approach. The Spring Cloud Contract Verifier is used as a tool that enables the development of Consumer Driven Contracts. Spring Cloud Contract Verifier is used with Contract Definition Language (DSL) written in Groovy or YAML.

Contract definitions are used to produce following resources:

  • By default JSON stub definitions are to be used by WireMock (HTTP Server Stub) when doing integration testing on the client code (client tests). Test code must still be written by hand, and test data is produced by Spring Cloud Contract Verifier.
  • Messaging routes if you’re using one. We’re integrating with Spring Integration, Spring Cloud Stream, and Apache Camel. You can however set your own integrations if you want to.
  • Acceptance tests (by default in JUnit or Spock) are used to verify if the server-side implementation of the API is compliant with the contract (server tests). The full test is generated by Spring Cloud Contract Verifier.

Spring Cloud Contract Verifier features:

  • Ensure that HTTP / Messaging stubs (used when developing the client) are doing exactly what actual server-side implementation will promote acceptance test driven development method and Microservices architectural style
  • To provide a way to publish changes in contracts that are immediately visible on both sides of the communication
  • To generate boilerplate test code used on the server side

Disadvantage:

  • To test one microservice we would have to deploy all microservices, a couple of databases, etc.

Reference: https://spring.io/,https://skolaparthi.com/spring-retry/

vasu34k

Share
Published by
vasu34k

Recent Posts

Generative AI

Generative AI is a type of AI (such as ChatGPT) that can generate new forms…

5 months ago

Pair Programming

Pair programming is a software development technique in which two programmers work together at one…

5 months ago

AWS CodeWhisperer

Amazon recently released Amazon CodeWhisperer to the public. It is an AWS real-time AI code generator…

5 months ago

Multi-hop architecture Azure

Multi-hop architecture is a design approach for organizing data in the Delta warehouse. Multi-hop architectures…

9 months ago

MuleSoft Accelerators

MuleSoft Accelerators are predefined Mule applications, API specifications, and documentation that help to speed up the implementation life…

9 months ago

Introduction to OpenAPI

OpenAPI Specification also known as Swagger Specification is an API description format for REST APIs.…

1 year ago