Skip to content

Commit

Permalink
Add example for @RabbitListener with @QueueBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
stavshamir committed Mar 19, 2022
1 parent 9bd11c1 commit 0a8af98
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public Queue anotherQueue() {
return new Queue("another-queue", false);
}

@Bean
public Queue exampleBindingsQueue() {
return new Queue("example-bindings-queue", false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

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

@RabbitListener(bindings = {
@QueueBinding(
exchange = @Exchange(name = "name", type = ExchangeTypes.TOPIC),
value = @Queue(name = "example-bindings-queue"))
})
public void bindingsExample(AnotherPayloadDto payload) {
logger.info("Received new message in example-bindings-queue: {}", payload.toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
}
},
"channels": {
"example-bindings-queue": {
"publish": {
"bindings": {
"amqp": {
"expiration": 0,
"priority": 0,
"deliveryMode": 0,
"mandatory": false,
"timestamp": false,
"ack": false
}
},
"message": {
"name": "io.github.stavshamir.springwolf.example.dtos.AnotherPayloadDto",
"title": "AnotherPayloadDto",
"payload": {
"$ref": "#/components/schemas/AnotherPayloadDto"
}
}
}
},
"another-queue": {
"publish": {
"bindings": {
Expand Down Expand Up @@ -57,6 +78,25 @@
},
"components": {
"schemas": {
"AnotherPayloadDto": {
"type": "object",
"properties": {
"foo": {
"type": "string"
},
"example": {
"$ref": "#/components/schemas/ExamplePayloadDto"
}
},
"example": {
"foo": "string",
"example": {
"someString": "string",
"someLong": 0,
"someEnum": "FOO1"
}
}
},
"ExamplePayloadDto": {
"type": "object",
"properties": {
Expand All @@ -81,25 +121,6 @@
"someLong": 0,
"someEnum": "FOO1"
}
},
"AnotherPayloadDto": {
"type": "object",
"properties": {
"foo": {
"type": "string"
},
"example": {
"$ref": "#/components/schemas/ExamplePayloadDto"
}
},
"example": {
"foo": "string",
"example": {
"someString": "string",
"someLong": 0,
"someEnum": "FOO1"
}
}
}
}
}
Expand Down

0 comments on commit 0a8af98

Please sign in to comment.