Coder Social home page Coder Social logo

mduesterhoeft / testing-asynchonous-interactions Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 4.0 72 KB

sample application code of the blog post Testing asynchronous interactions in distributed systems using Spring Cloud Contract published in the epages developer blog

Home Page: https://developer.epages.com/blog/2017/01/17/how-to-test-eventbased-services-using-contracts.html

Java 97.77% Groovy 2.23%
spring-cloud-contract rabbitmq spring-amqp

testing-asynchonous-interactions's Introduction

Testing asynchronous interactions in distributed systems using Spring Cloud Contract

This is a sample application code of the blog post Testing asynchronous interactions in distributed systems using Spring Cloud Contract published in the epages developer blog.

It illustrates how Spring Cloud Contract can be used to test asynchronous service interactions.

Please see the blog post for details.

Run the application

A docker-compose setup exists to start the product-service, the checkout-service, and RabbitMQ.

First build the services to generate the jar files. And then use docker-compose to start the services.

cd <checkout-directory>/product-service
./gradlew check bootRepackage

For the product service we also need to make sure that the contracts have been published to the local maven repository.

./gradlew publishToMavenLocal
cd <checkout-directory>/checkout-service
./gradlew check bootRepackage
docker-compose up -d

Create a Product and add it to a cart

We use httpie as command line HTTP client.

Create a product

http POST <docker-ip>:8081/products name=some salesPrice=49.99 purchasePrice=39.99

Create a cart

http POST <docker-ip>:8082/carts

Use the uri in the location header for the next request

Add a product to the cart

The product data should be available in the cart now and we should be able to add it.

http PUT <docker-ip>:8082/carts/1 quantity=2 productId=1

testing-asynchonous-interactions's People

Contributors

mduesterhoeft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

testing-asynchonous-interactions's Issues

How to approach testing different queues via routingKey?

Hi Mathias,
Thank you very much for providing such a useful blogpost and test resources!

I selected your approach of the Spring Cloud Contract dependency to start testing a distributed system, which depends on a running rabbitmq.

Unfortunately my stubs create messages, which are distributed in all message consumer queues... but in the existing service-architecture I used Topic Exchanges with specified routing keys, which only forwards selected messages to the defined queue.

Is there any way to reproduce this scenario in your test cases?

My research so far:
Definition of a new header entry:

header('amqp_receivedRoutingKey': 'requested')

https://stackoverflow.com/questions/51420639/spring-cloud-contract-with-spring-amqp

But the consumer service forwards the message-stub in ALL existing queues. So I have no control to test our "contracts" properly.

Do you have a suggestion where to dive in? Or is my requirement too sophisticated?

I also found out, that the dependency version 1.2.4.RELEASE offers the functionality to include routingKeys... but after I try to use the new Version the test fails with: Caused by: java.lang.ClassNotFoundException: org.springframework.cloud.contract.verifier.converter.YamlContractConverter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.