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, featuring:

  • Auto-generated documentation
  • Dynamically generated network diagrams so you can see which services talk to which other services.
  • The ability to tag a version of a pact Pact (i.e. "prod") so a Provider can verify itself against a fixed version of a Pact to ensure backwards compatibility.
  • The ability to use tags to allow development of new features without breaking your mainline development Pact.
  • Webhooks to trigger provider builds when a Pact is published.
  • Provider verification results display
  • Change tracking between Pact versions so you can tell when a consumer has changed its expectations.

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.

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

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:

$Headers = @{
  Authorization = "Basic $([System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")))"
}
$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.

results matching ""

    No results matching ""