liveBook · Manning

Contract broker

As explained in Contract Testing in Action

Pact Broker is a service for sharing and managing Pact contracts, contract versions, and provider verification results between consumers and providers.

When consumer and provider code live in separate repositories, passing contract files around quickly becomes unreliable: versions diverge, updates need manual notification, and teams lose sight of what has been verified. A contract broker is the shared service that stores those contracts and coordinates their life cycle. In Pact-based consumer-driven contract testing, it records consumer and provider versions, contract metadata, and provider verification results. section 3.4 section 9.1

The broker is not the system that tests an API. A consumer test generates a contract from interactions with a mock provider, then publishes that contract and its version. The real provider retrieves it, replays the requests against its running service, compares actual and expected responses, and publishes the verification result back. The consumer can then check whether that specific contract version is safe to deploy. section 1.5.1 section 1.5.2 section 3.5

A broker supports a release workflow by keeping four responsibilities separate:

  • Store contracts independently of consumer and provider repositories, including versions and metadata. section 3.4
  • Give providers the contract version needed for verification and retain the resulting status. section 3.5
  • Let CI/CD pipelines report whether changes are safe to deploy; failed verification sends developers back to fix and repeat. section 2.6.5
  • Show dependencies and version compatibility through a network diagram and verification matrix. section 9.1.1

Publishing a consumer contract to a hosted broker

After generating Pact files, configure the broker base URL and API token as environment variables, then run a Pact CLI publish command with a consumer application version. The newly uploaded contract starts unverified until the provider retrieves and verifies it. A managed PactFlow service is one way to host the broker. section 4.4 section 9.2

Figure 3.5 CDCT life cycle from a JavaScript web application, through the broker to Java API or event service, and finally using the can-i-deploy tool to verify the changes in the web application
figure

The lifecycle view connects consumer publication, provider verification, broker status updates, and the final can-i-deploy check. section 3.5

Choose hosting based on operational needs. PactFlow supplies a managed service, bearer-token authentication, and additional features; self-hosted open-source Pact Broker offers control and flexibility but requires infrastructure, security patches, dependency updates, and maintenance. A Docker deployment uses a PostgreSQL dependency and can provide the core broker locally or within existing infrastructure. section 9.5 section 9.4.1

How Contract Testing in Action covers it

How deep it goes
Explains the full publication-to-verification workflow, core visualizations, hosting choices, and a Docker-based self-hosted setup.
Examples
Uses web and mobile consumers, a Java API or event service, PactFlow publication, and a Docker Compose broker backed by PostgreSQL.
What it assumes
Assumes consumer and provider contract tests exist, then teaches broker publication, verification flow, and deployment-status checking from that point.
What you can do after
Operate/configure it by publishing versioned contracts, retrieving them for provider verification, checking deployment status, and selecting hosted or self-hosted deployment.
How it connects
Connects consumer-driven contract testing with consumer tests, provider verification, CI/CD, can-i-deploy, PactFlow, Docker, Kubernetes, and PostgreSQL.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Contract Testing in Action. The section links point to the parts of the book it draws on.