Pact broker : the missing piece of your Consumer-Driven Contract approach (3/3) [ENGLISH] | Agile Partner
share on

Pact broker : the missing piece of your Consumer-Driven Contract approach (3/3)

By Yoan Thirion, Agile coach and Craftsman at Agile Partner.

The Pact Broker is an application for sharing for consumer driven contracts and verification results.

It is optimized for use with “pacts” (contracts created by the Pact framework), but can be used for any type of contract that can be serialized to JSON.

1*XVyMF-kIZzzeYoAsLIphjw

Let’s deep dive into the functionalities offered by the broker :

A RESTful API for publishing and retrieving pacts

The question that you can ask yourself when you start a CDC approach is where do I store the contracts ? In the consumer repository ? in a dedicated repository for the contracts ? in external libraries ? Where ?

The broker has been implemented to solve this question. The only source of truth is the broker where I can :

  • Publish a contract
0*H01GYuDB_KH0N7ue
  • Retrieve a contract
0*1JTWJB1WP13Bk0DH

An embedded API browser for navigating the API

The Pact Broker API uses HAL (Hypertext Application Language) as its hypermedia implementation (that is, the method of providing links within a resource to navigate from that resource to related resources).

The Broker comes with an embedded HAL browser that lets you navigate the API in your browser window by using the HAL relations in each resource.

The HAL specification also provides a built in method for providing documentation about a relation. You can navigate to this documentation in the HAL browser by clicking on the book icon next to that relation in the HAL browser.

0*nJsHl2oCQrX4g3Cx

Displays provider verification results

When a pact is verified against a provider, the outcome of that verification (pass or fail) needs to be made available to the consumer and provider teams, so they know whether or not the code in either project can be safely deployed.

The pact verification tool can automatically publish the verification results back to the broker, and they will be displayed on the index page next to the pact details.

By displaying verification results you know if you can deploy safely.

0*fSkF1xDSb8BFurkA

Auto-generated documentation for each contract

A human readable version of the pact can be browsed from the broker :

0*-ULItnkxeIT2wXyf

Provides a “matrix” of compatible consumer and provider versions

When publishing a pact or a verification, the resource is associated with a particular version of the pacticipant (application), which is identified by a version number.

A pacticipant version number:

  • is expected to change (almost) every time a pact is published
  • should uniquely identify or be able to be mapped back to the commit of the code base that published a pact or verification (so that you can use tags to identify and checkout the the prod version of your provider if you wish to test the "matrix".)
  • should exist only on one branch of your code
  • should be known at release time (so you can pass it in to can-i-deploy to ensure that you are safe to release)
0*xVjgRFSpwfmWoD39

Visualize your microservices

Dynamically generated network diagrams so you can visualise your microservice network.

0*oZ_pWavLK4kMs_7b

A CLI for your CI/CD

A CLI for encorporating the Pact workflow into your continuous integration process.

By using the can-i-deploy feature of the Pact Broker CLI, it will give you a definitive answer if the version of your consumer that is being deployed, is compatible with all of its providers.

This functionality can definitely save your life by avoiding an integration problem to arrive in production.

0*W2VlBA4akqASssl0

Docker Pact Broker

There is an official image for the broker available here : https://hub.docker.com/r/pactfoundation/pact-broker/

So it is really easy to setup and play with it with just a few lines of YAML :

0*TAmqtGUcrfQ5xNeY

Webhooks

Provides webhooks to trigger actions when pacts change eg. run provider build, notify a Slack channel.

You can trigger a webhook for those events :

1*kM3tnkoHPfTCTC_PeCBrbQ-2

To create a new webhook you just need to POST it to your broker :

1*R5MmJPkt6vkZne8nH63iHA

In the broker you will have feedback on it :

1*NY2boRVp36DyTVtyjB_n6A

To conclude those articles I would like to say that Pact and Pact broker together are really great tools BUT I would like to remind that consumer-driven contract testing is a technique that requires no special tool to implement. If you want to start without tooling go ahead, tools are just there to support the approach.

Once again it is all about communication.

Communication between teams :

  • Team that will need to consume a service
  • Team that will provide the service

Need help with your microservices? Want to learn more?

share on