
Explore how Spring Cloud Contract extends testing from HTTP to message based communications, and preview a three-section course covering a prepared consumer and producer project, RabbitMQ basics, and contract testing.
Explore a two-app project that models a bus as the producer and a bus stop as the consumer, using a queue to carry location messages and compute the eta.
Expose producer side code for sending bus location events to RabbitMQ with Spring Boot; the location sender publishes JSON payloads with lat/long and headers every five seconds.
Explore the consumer side of contract testing with Spring Cloud Contract, using a location receptor to process bus events from RabbitMQ and compute ETAs via an arrival time estimator.
Explore the basics of RabbitMQ, including exchanges, queues, and bindings, and learn how direct, topic, fanout, and headers exchanges route messages by routing keys and binding keys.
Implement a RabbitMQ producer by wiring a messaging template, configuring the exchange, queue, and binding, and sending JSON messages with a converter to the broker.
Implement rabbitmq on the consumer side by using a rabbit listener to a target queue and deserializing json messages into a bus event. Use a Jackson json converter.
Create a producer-side contract for contract testing, defining a groovy script, a labeled input trigger, a payload with bus number, route number, location, and headers including content type.
Configure contract testing with the Spring Cloud Contract plugin, generate unit tests from contracts, and implement a base test class to trigger message publishing via the location sender.
Create a test configuration with a custom contract verifier messaging and a rabbit message verifier receiver to test the producer side, enabling header validation.
Perform an integration test on the consumer side with spring cloud contracts, triggering a stop to publish a contract-based message to a rabbitmq queue and verify the arrivals repo.
In our previous course, Contract Testing with Spring Cloud Contract, we delved into how Spring Cloud Contracts can be a powerful tool for creating reliable contract tests specifically for HTTP communications. By implementing these tests, you can provide confidence to your team during production releases and create solid integration tests that reduce dependencies on other teams. However, contract testing with Spring Cloud Contracts isn’t limited to just HTTP. This course focuses on extending the power of contract testing to message-based communication—a critical area for ensuring stability and reliability in distributed systems.
We’ll take you through hands-on examples using two small applications that communicate through RabbitMQ, guiding you in setting up contract tests for these message-based integrations. If RabbitMQ is new to you, there’s no need to worry; we’ll start with a primer on RabbitMQ basics before diving into the contract testing specifics. After this course, you will be able to implement contract testing regardless of the message broker your project is using (Kafka, ActiveMQ, SQS, etc).
To fully harness the value of this course, you should ideally have a foundation in Java, basic Spring Boot, and be familiar with unit testing concepts, particularly with tools like Mockito and JUnit. This background will help you maximize the course's insights and apply them effectively to your own projects.