Spring-cloud-contract: Make SpringAmqpStubMessages RoutingKey aware

Created on 20 Mar 2018  路  9Comments  路  Source: spring-cloud/spring-cloud-contract


We have Services which consumes multiple queues from one exchange but each queue with a different routingKey.

I know questionable but that's our status quo.

e.G

exchange: something

routingKeys:
        failed:
        rejected:
        created:

My problem is that the consumer contract test will broadcast it to every queue with the correct destination whilst ignoring the routingKey.


My temporary fix was adding a routingKey capture instead of an anyString() matcher on
org/springframework/cloud/contract/verifier/messaging/amqp/SpringAmqpStubMessages.java:82
applying it to the header with the AmqpHeaders.RECEIVED_ROUTING_KEY key.

And adding some logic on
org/springframework/cloud/contract/verifier/messaging/amqp/MessageListenerAccessor.java:62
using that header.

So i can set header('amqp_receivedRoutingKey':routingKey) on my producer contracts.

bug

Most helpful comment

thanks for the hints @KazuoD and @r0bse - hopefully it's fixed :)

All 9 comments

Which version of Contract are you referring to? Do you think you could produce a sample to reproduce the problem? Or better, a test in Contract? Or even better, suggest a PR? :D

Thanks for your fast response.

Which version of Contract are you referring to?

we are using 1.2.0.RELEASE

Do you think you could produce a sample to reproduce the problem? Or better, a test in Contract?

Yep i could do that when i have some time. I will link the project than.

Or even better, suggest a PR? :D

Would be glad to do so :)

Cool! Also try checking if the problem is still there when you use Contract's latest snapshots.

Good idea, will do that

colleague of mine just tested it with the latest release/snapshot 2.0.0.M7
Problem still exists.

I'll suggest a PR in the coming days.

Hi,

I worked with KazouD on the problem, or to be more precise he fixed it for me :-)

The problem is described in an example project at: https://github.com/r0bse/contract-amqp-messaging
The latest SNAPSHOT version still has the same problem (in branch _amqp_routingkey_with_contract_SNAPSHOT_)

The fix from KazouD is implemented in branch _amqp_contract_fix_

thanks for the hints @KazuoD and @r0bse - hopefully it's fixed :)

@marcingrzejszczak

Thanks a lot :D we finally can write more contract tests

Thank you!

Was this page helpful?
0 / 5 - 0 ratings