@Bean
+public Binding binding() {
+ return BindingBuilder.bind(new Queue("test.queue")).to(new DirectExchange("contract-test.exchange")).with("#");
+}
+diff --git a/spring-cloud-contract.html b/spring-cloud-contract.html index 3a532df273..6687382a57 100644 --- a/spring-cloud-contract.html +++ b/spring-cloud-contract.html @@ -719,7 +719,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
Documentation Authors: Adam Dudczak, Marcin Grzejszczak, Jakub Kubryński, Karol Lassak, -Olga Maciaszek-Sharma, Mariusz Smykuła, Dave Syer
+Olga Maciaszek-Sharma, Mariusz Smykuła, Dave Syer, Mathias Düsterhöft1.0.2.BUILD-SNAPSHOT
@@ -5235,26 +5235,24 @@ For the provided artifacts it will automatically download the stubs and register routes.The integration tries to work standalone, that is without interaction with a running RabbitMQ message broker. It expects a RabbitTemplate on the application context and uses it as a spring boot test @SpyBean.
+
The integration tries to work standalone, that is without interaction with a running RabbitMQ message broker.
+It expects a RabbitTemplate on the application context and uses it as a spring boot test @SpyBean.
Thus it can use the mockito spy functionality to verify and introspect messages sent by the application.
|
- Important
- |
-
-In the current status of the implementation tries to find a MessageListenerAdapter on the application context to send messages into the application, because we want to avoid interacting with a running bus.
-Using annotation driven listener endpoints (e.g. @RabbitListener annotated listener methods) is currently not supported.
- |
-
On the message consumer side, it considers all @RabbitListener annotated endpoints as well as all `SimpleMessageListenerContainer`s on the application context.
As messages are usually sent to exchanges in AMQP the message contract contains the exchange name as the destination. +Message listeners on the other side are bound to queues. Bindings connect an exchange to a queue. +If message contracts are triggered the Spring AMQP stub runner integration will look for bindings on the application context that match this exchange. +Then it collects the queues from the Spring exchanges and tries to find messages listeners bound to these queues. +The message is triggered to all matching message listeners.
It’s enough to have both Spring AMQP and Spring Cloud Contract Stub Runner on classpath. +
It’s enough to have both Spring AMQP and Spring Cloud Contract Stub Runner on the classpath.
Remember to annotate your test class with @AutoConfigureMessageVerifier.
stubTrigger.trigger("contract-test.person.created.event")
The message has the destination contract-test.exchange so the Spring AMQP stub runner integration looks for bindings related to this exchange.
@Bean
+public Binding binding() {
+ return BindingBuilder.bind(new Queue("test.queue")).to(new DirectExchange("contract-test.exchange")).with("#");
+}
+The binding definition binds the queue test.queue.
+So the following listener definition is a match and is invoked with the contract message.
@Bean
+public SimpleMessageListenerContainer simpleMessageListenerContainer(ConnectionFactory connectionFactory,
+ MessageListenerAdapter listenerAdapter) {
+ SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
+ container.setConnectionFactory(connectionFactory);
+ container.setQueueNames("test.queue");
+ container.setMessageListener(listenerAdapter);
+
+ return container;
+}
+Also, the following annotated listener represents a match and would be invoked.
+@RabbitListener(bindings = @QueueBinding(
+ value = @Queue(value = "test.queue"),
+ exchange = @Exchange(value = "contract-test.exchange", ignoreDeclarationExceptions = "true")))
+public void handlePerson(Person person) {
+ this.person = person;
+}
+|
+ Note
+ |
+
+The message is directly handed over to the onMessage method of the MessageListener associated with the matching SimpleMessageListenerContainer.
+ |
+