Skip to content

Commit 0a8af98

Browse files
committed
Add example for @RabbitListener with @QueueBinding
1 parent 9bd11c1 commit 0a8af98

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/configuration/RabbitConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public Queue anotherQueue() {
2626
return new Queue("another-queue", false);
2727
}
2828

29+
@Bean
30+
public Queue exampleBindingsQueue() {
31+
return new Queue("example-bindings-queue", false);
32+
}
33+
2934
}

springwolf-examples/springwolf-amqp-example/src/main/java/io/github/stavshamir/springwolf/example/consumers/ExampleConsumer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto;
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
7+
import org.springframework.amqp.core.ExchangeTypes;
8+
import org.springframework.amqp.rabbit.annotation.Exchange;
9+
import org.springframework.amqp.rabbit.annotation.Queue;
10+
import org.springframework.amqp.rabbit.annotation.QueueBinding;
711
import org.springframework.amqp.rabbit.annotation.RabbitListener;
812
import org.springframework.stereotype.Service;
913

@@ -22,4 +26,13 @@ public void receiveAnotherPayload(AnotherPayloadDto payload) {
2226
logger.info("Received new message in another-queue: {}", payload.toString());
2327
}
2428

29+
@RabbitListener(bindings = {
30+
@QueueBinding(
31+
exchange = @Exchange(name = "name", type = ExchangeTypes.TOPIC),
32+
value = @Queue(name = "example-bindings-queue"))
33+
})
34+
public void bindingsExample(AnotherPayloadDto payload) {
35+
logger.info("Received new message in example-bindings-queue: {}", payload.toString());
36+
}
37+
2538
}

springwolf-examples/springwolf-amqp-example/src/test/resources/asyncapi.json

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@
1212
}
1313
},
1414
"channels": {
15+
"example-bindings-queue": {
16+
"publish": {
17+
"bindings": {
18+
"amqp": {
19+
"expiration": 0,
20+
"priority": 0,
21+
"deliveryMode": 0,
22+
"mandatory": false,
23+
"timestamp": false,
24+
"ack": false
25+
}
26+
},
27+
"message": {
28+
"name": "io.github.stavshamir.springwolf.example.dtos.AnotherPayloadDto",
29+
"title": "AnotherPayloadDto",
30+
"payload": {
31+
"$ref": "#/components/schemas/AnotherPayloadDto"
32+
}
33+
}
34+
}
35+
},
1536
"another-queue": {
1637
"publish": {
1738
"bindings": {
@@ -57,6 +78,25 @@
5778
},
5879
"components": {
5980
"schemas": {
81+
"AnotherPayloadDto": {
82+
"type": "object",
83+
"properties": {
84+
"foo": {
85+
"type": "string"
86+
},
87+
"example": {
88+
"$ref": "#/components/schemas/ExamplePayloadDto"
89+
}
90+
},
91+
"example": {
92+
"foo": "string",
93+
"example": {
94+
"someString": "string",
95+
"someLong": 0,
96+
"someEnum": "FOO1"
97+
}
98+
}
99+
},
60100
"ExamplePayloadDto": {
61101
"type": "object",
62102
"properties": {
@@ -81,25 +121,6 @@
81121
"someLong": 0,
82122
"someEnum": "FOO1"
83123
}
84-
},
85-
"AnotherPayloadDto": {
86-
"type": "object",
87-
"properties": {
88-
"foo": {
89-
"type": "string"
90-
},
91-
"example": {
92-
"$ref": "#/components/schemas/ExamplePayloadDto"
93-
}
94-
},
95-
"example": {
96-
"foo": "string",
97-
"example": {
98-
"someString": "string",
99-
"someLong": 0,
100-
"someEnum": "FOO1"
101-
}
102-
}
103124
}
104125
}
105126
}

0 commit comments

Comments
 (0)