This workshop should take about 2 hours, depending on how deep you want to go into each topic.
This workshop is setup with a number of steps that can be run through. Each step is in a branch, so to run through a step of the workshop just check out the branch for that step (i.e. git checkout step1
).
NOTE: Each step is tied to, and must be run within, a git branch, allowing you to progress through each stage incrementally. For example, to move to step 2 run the following: git checkout step2
There are two components in scope for our workshop.
We need to first create an HTTP client to make the calls to our provider service:
The Consumer has implemented the product service client which has the following:
GET /products
- Retrieve all productsGET /products/{id}
- Retrieve a single product by IDThe diagram below highlights the interaction for retrieving a product with ID 10:
You can see the client interface we created in consumer/src/main/au/com/dius/pactworkshop/consumer/ProductService.java
:
@Service public class ProductService { private final RestTemplate restTemplate; @Autowired public ProductService(RestTemplate restTemplate) { this.restTemplate = restTemplate; } public List<Product> getAllProducts() { return restTemplate.exchange("/products", HttpMethod.GET, null, new ParameterizedTypeReference<List<Product>>(){}).getBody(); } public Product getProduct(String id) { return restTemplate.getForEntity("/products/{id}", Product.class, id).getBody(); } }
We can run the client with ./gradlew consumer:bootRun
- it should fail with the error below, because the Provider is not running.
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8085/products": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
Move on to step 2
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4