When keeping contracts in an external repository, and by following the
stubs per consumer feature, we have the full knowledge of who is
calling who within our system. That way we can sketch a graph of dependencies
between applications.
As a reminder, the stubs per consumer feature is all about creating a
consumer subfolder, in each producer's folder. E.g. if consumer baz uses producer foo.bar
then the folder structure would look like this foo/bar/baz/contracts/....
Let's assume that we have such setup (... signifies contract definitions):
โโโ com
โย ย โโโ example
โย ย โโโ beer-api-producer-external
โย ย โโโ 1.0.0
โย ย โย ย โโโ beer-api-consumer
โย ย โย ย โย ย โโโ messaging
โย ย โย ย โย ย โย ย โโโ ...
โย ย โย ย โย ย โโโ rest
โย ย โย ย โย ย โโโ ...
โย ย โย ย โโโ mvnw
โย ย โย ย โโโ pom.xml
โย ย โโโ 2.0.0
โย ย โโโ anotherConsumerOnly
โย ย ย ย โย ย โโโ ...
โย ย โโโ barService
โย ย ย ย โย ย โโโ ...
โย ย โโโ foo.bar.bazService
โย ย ย ย โย ย โโโ ...
โย ย โโโ foo.bar.consumerOnly
โย ย ย ย โย ย โโโ ...
โย ย โโโ foo.bar.fooService.1_2_3
โย ย ย ย โย ย โโโ ...
โย ย โโโ pom.xml
โโโ foo
โโโ bar
โโโ barService
โย ย โโโ pom.xml
โย ย โโโ yetAnotherConsumer
โย ย ย ย โโโ ...
โโโ bazService
โย ย โโโ bazConsumer1
โย ย โย ย โโโ rest
โย ย โย ย โโโ ...
โย ย โโโ pom.xml
โโโ beer-api-consumer
โย ย โโโ messaging
โย ย โย ย โโโ ...
โย ย โโโ pom.xml
โย ย โโโ rest
โย ย โโโ ...
โโโ fooService
โโโ 1.2.3
ย ย โโโ ...
โโโ pom.xml
We can reason that:
com.example:beer-api-producer-external in version 2.0.0 is used by 5 consumersfoo.bar:bazServicefoo.bar:barServiceanotherConsumerOnlyfoo.bar:fooService in version 1.2.3foo.bar:consumerOnlycom.example:beer-api-producer-external in version 1.0.0 is used by 1 consumerfoo.bar:beer-api-consumerfoo.bar:bazService is used by 1 consumerbazConsumer1foo.bar:barService is used by 1 consumeryetAnotherConsumerThis information gives as all data we need to sketch a graph of the dependencies.
_Example of d3 graph_

_Example of Dracula graph_

It's enough to execute the https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/beer_contracts/src/test/java/docs/GenerateGraphFromContractsTests.java. The test scans the contract structure and builds a graph of relationships between consumers and producers.
It will create a file called relationships.js (https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/beer_contracts/relationships.js) that you can source in your HTML file. It will load to a var called relationships the JSON representing the relationships. The JSON consists of source, target pairs where source is the producer and target is the consumer.
There are two example HTML files relationships_d3.html (https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/beer_contracts/relationships_d3.html) that uses http://d3js.org/ and relationships_dracula.html (https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/beer_contracts/relationships_dracula.html) that uses https://www.graphdracula.net to render the graph.
.producer_contracts that will tell the test thatpom.xmlbuild.gradle file (you need it anyways to, as a consumer, install stubs of the producer)Wow very cool (more & more like Pact ;) )
I need to look at the "how to store contracts" (like external repository)
@ygrenzinger the main difference is that you don't need a separate machinery (Pact Broker) to sketch the diagram. We created https://github.com/Codearte/accurest (the predecessor of Spring Cloud Contract) because of the verbosity of Pact and forcing of consumer contract approach. We didn't think that the consumer contract process is efficient.
I'm more than certain that there's a lot of companies where this approach is great and Pact really did an amazing job in promoting Contract Tests. However, we felt we can do sth in a way that better suits our way of doing things.
So in this case, just by following a convention, you can get a graph of dependencies for free. You already use Git, so you don't need to deploy anything else, you don't have to support the code etc. With Spring Cloud Contract we are doing our best to go with as simple solutions as possible. If you're in the Java world you already use Artifactory / Nexus so we just reuse it. With the Git Stub Downloader you don't even need Artifactory / Nexus to store your stubs cause we store it in Git for you.
And for sure that's not the end of enhancements that should be very simple to use and give you more features :)
Most helpful comment
@ygrenzinger the main difference is that you don't need a separate machinery (Pact Broker) to sketch the diagram. We created https://github.com/Codearte/accurest (the predecessor of Spring Cloud Contract) because of the verbosity of Pact and forcing of consumer contract approach. We didn't think that the consumer contract process is efficient.
I'm more than certain that there's a lot of companies where this approach is great and Pact really did an amazing job in promoting Contract Tests. However, we felt we can do sth in a way that better suits our way of doing things.
So in this case, just by following a convention, you can get a graph of dependencies for free. You already use Git, so you don't need to deploy anything else, you don't have to support the code etc. With Spring Cloud Contract we are doing our best to go with as simple solutions as possible. If you're in the Java world you already use Artifactory / Nexus so we just reuse it. With the
Git Stub Downloaderyou don't even need Artifactory / Nexus to store your stubs cause we store it in Git for you.And for sure that's not the end of enhancements that should be very simple to use and give you more features :)