Sharing Pacts

At some point in your Pact journey, you are going to be generating lots of Pact files for your Provider to verify, ensuring the Provider has access to the latest version of the Pacts at all times. This is great, but very quickly this becomes cumbersome to manage.

Pact Broker

This is where the Pact Broker comes in. It enables you to share your Pacts between projects, and make them useful for people too. It is the recommended way forward for serious Pact development.

It:

  • allows you to release customer value quickly and confidently by deploying your services indendently and avoiding the bottleneck of integration tests
  • solves the problem of how to share contracts and verification results between consumer and provider projects
  • tells you which versions of your applications can be deployed safely together
  • automatically versions your contracts
  • allows you to ensure backwards compatibility between multiple consumer and provider versions (eg. in a mobile or multi-tenant environment)
  • provides API documentation of your applications that is guaranteed to be up-to date
  • shows you real examples of how your services interact
  • allows you to visualise the relationships between your services

Features:

  • A RESTful API for publishing and retrieving pacts.
  • An embedded API browser for navigating the API.
  • Autogenerated documentation for each pact.
  • Dynamically generated network diagrams so you can visualise your microservice network.
  • Displays provider verificaton results so you know if you can deploy safely.
  • Provides a “matrix” of compatible consumer and provider versions, so you know which versions can be safely deployed together.
  • Provides badges to display pact verification statuses in your READMEs.
  • Enables an application version to be tagged (ie. “prod”, “feat/customer-preferences”) to allow repository-like workflows.
  • Provides webhooks to trigger actions when pacts change eg. run provider build, notify a Slack channel.
  • View diffs between Pact versions so you can tell what expectations have changed.
  • Docker Pact Broker
  • A CLI for encorporating the Pact workflow into your continuous integration process.

Most importantly, the Pact Broker allows you to easily decouple the release cycle of your Consumer and Provider, which is one of the goals of writing microservices in the first place.

Getting started

Read the pages in the Pact Broker quick start guide to get up and running with the basics. You’ll find a helpful checklist of changes you need to make to integrate Pact into your CI pipeline, as well as links to more detailed information on Broker usage.

You can find all the documentation for the Pact Broker in the Pact Broker wiki.

Our sponsor DiUS has kindly provided a free hosted broker to get you started quickly.

Language support

Command line interface

For Mac, Windows and Linux. Allows you to integrate the contracts workflow into your CI. Download here.

Ruby
via the pact_broker-client gem:

Pact JVM - Gradle

Pact JVM - JUnit

Pact JVM - SBT

Pact JVM - Maven

Golang

Pact JS

Pact .NET

Publishing

Example publishing with PowerShell:

  1. $Headers = @{
  2. Authorization = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")))"
  3. }
  4. $res = Invoke-WebRequest -Uri "https://test.pact.dius.com.au/pacts/provider/Animal%20Profile%20Service/consumer/Matching%20Service/version/1.0.0" -Headers $Headers -Method Put -InFile .\matching_service-animal_profile_service.json -ContentType "application/json"

See the full API.

Manual via HTTP

For more information head over to the Pact Broker website.

Alternative approaches

1. Consumer CI build commits pact to Provider codebase

Pretty self explanatory.

2. Publish pacts as CI build artefacts

Work out the URL to the pact created by the most recent successful build, and configure the pact:verify task to point to this URL.

3. Use Github/Bitbucket URL

This only works for repositories that don’t require authentication to read. Make sure that you always regenerate the pacts before committing if you make any changes to the pact specs, and that the specs are always passing before you commit, because you don’t want to verify the pact from a broken build.

4. Publish pacts to Amazon S3

Pact::Retreaty is a tool which provides a ultra light mechanism for
pushing and pulling pact contracts to/from S3.