-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Units test to investigate AMQP generation #790
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ringwolf-amqp-example/src/main/java/io/github/springwolf/examples/amqp/AmqpConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.examples.amqp; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class AmqpConstants { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add constant to ease navigation in code |
||
|
||
// Exchanges | ||
|
||
public static final String EXCHANGE_EXAMPLE_TOPIC_EXCHANGE = "example-topic-exchange"; | ||
public static final String EXCHANGE_CRUD_TOPIC_EXCHANGE_1 = "CRUD-topic-exchange-1"; | ||
public static final String EXCHANGE_CRUD_TOPIC_EXCHANGE_2 = "CRUD-topic-exchange-2"; | ||
/** | ||
* Direct Exchange - Routing is based on 'Routing key'. | ||
* Messages are 'routed' towards queue which name is equals to 'routing key' <BR/> | ||
* Note:<BR/> | ||
* The 'Default exchange' is a 'Direct exchange' with an empty name ( name= "") | ||
*/ | ||
public static final String EXCHANGE_DEFAULT_EXCHANGE = ""; | ||
|
||
// Routing keys | ||
|
||
/** | ||
* When a queue is bound with "#" (hash) binding key, | ||
* it will receive all the messages, regardless of the routing key - like in fanout exchange. | ||
*/ | ||
public static final String ROUTING_KEY_ALL_MESSAGES = "#"; | ||
|
||
public static final String ROUTING_KEY_CRUD = "crud-routing-key"; | ||
public static final String ROUTING_KEY_EXAMPLE_TOPIC_ROUTING_KEY = "example-topic-routing-key"; | ||
|
||
// Queues | ||
|
||
public static final String QUEUE_EXAMPLE_QUEUE = "example-queue"; | ||
public static final String QUEUE_ANOTHER_QUEUE = "another-queue"; | ||
public static final String QUEUE_MULTI_PAYLOAD_QUEUE = "multi-payload-queue"; | ||
public static final String QUEUE_EXAMPLE_BINDINGS_QUEUE = "example-bindings-queue"; | ||
|
||
public static final String QUEUE_CREATE = "queue-create"; | ||
public static final String QUEUE_READ = "queue-read"; | ||
public static final String QUEUE_DELETE = "queue-delete"; | ||
public static final String QUEUE_UPDATE = "queue-update"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.examples.amqp.consumers; | ||
|
||
import io.github.springwolf.examples.amqp.AmqpConstants; | ||
import io.github.springwolf.examples.amqp.dtos.AnotherPayloadDto; | ||
import io.github.springwolf.examples.amqp.dtos.ExamplePayloadDto; | ||
import io.github.springwolf.examples.amqp.dtos.GenericPayloadDto; | ||
import io.github.springwolf.examples.amqp.producers.AnotherProducer; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.amqp.core.ExchangeTypes; | ||
import org.springframework.amqp.core.Message; | ||
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.messaging.handler.annotation.Payload; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
|
@@ -20,9 +24,9 @@ public class ExampleConsumer { | |
|
||
private final AnotherProducer anotherProducer; | ||
|
||
@RabbitListener(queues = "example-queue") | ||
@RabbitListener(queues = AmqpConstants.QUEUE_EXAMPLE_QUEUE) | ||
public void receiveExamplePayload(ExamplePayloadDto payload) { | ||
log.info("Received new message in example-queue: {}", payload.toString()); | ||
log.info("Received new message in {}: {}", AmqpConstants.QUEUE_EXAMPLE_QUEUE, payload.toString()); | ||
|
||
AnotherPayloadDto example = new AnotherPayloadDto(); | ||
example.setExample(payload); | ||
|
@@ -31,37 +35,106 @@ public void receiveExamplePayload(ExamplePayloadDto payload) { | |
anotherProducer.sendMessage(example); | ||
} | ||
|
||
@RabbitListener(queues = "another-queue") | ||
@RabbitListener(queues = AmqpConstants.QUEUE_ANOTHER_QUEUE) | ||
public void receiveAnotherPayload(AnotherPayloadDto payload) { | ||
log.info("Received new message in another-queue: {}", payload.toString()); | ||
log.info("Received new message in {}: {}", AmqpConstants.QUEUE_ANOTHER_QUEUE, payload.toString()); | ||
} | ||
|
||
@RabbitListener( | ||
bindings = { | ||
@QueueBinding( | ||
exchange = @Exchange(name = "example-topic-exchange", type = ExchangeTypes.TOPIC), | ||
exchange = | ||
@Exchange( | ||
name = AmqpConstants.EXCHANGE_EXAMPLE_TOPIC_EXCHANGE, | ||
type = ExchangeTypes.TOPIC), | ||
value = | ||
@Queue( | ||
name = "example-bindings-queue", | ||
name = AmqpConstants.QUEUE_EXAMPLE_BINDINGS_QUEUE, | ||
durable = "false", | ||
exclusive = "true", | ||
autoDelete = "true"), | ||
key = "example-topic-routing-key") | ||
key = AmqpConstants.ROUTING_KEY_EXAMPLE_TOPIC_ROUTING_KEY) | ||
}) | ||
public void bindingsExample(AnotherPayloadDto payload) { | ||
log.info( | ||
"Received new message in example-bindings-queue" | ||
+ " through exchange example-topic-exchange using routing key example-topic-routing-key: {}", | ||
"Received new message in {}" + " through exchange {}" + " using routing key {}: {}", | ||
AmqpConstants.QUEUE_EXAMPLE_BINDINGS_QUEUE, | ||
AmqpConstants.EXCHANGE_EXAMPLE_TOPIC_EXCHANGE, | ||
AmqpConstants.ROUTING_KEY_EXAMPLE_TOPIC_ROUTING_KEY, | ||
payload.toString()); | ||
} | ||
|
||
@RabbitListener(queues = "multi-payload-queue") | ||
@RabbitListener(queues = AmqpConstants.QUEUE_MULTI_PAYLOAD_QUEUE) | ||
public void bindingsBeanExample(AnotherPayloadDto payload) { | ||
log.info("Received new message in multi-payload-queue (AnotherPayloadDto): {}", payload.toString()); | ||
log.info( | ||
"Received new message in {} (AnotherPayloadDto): {}", | ||
AmqpConstants.QUEUE_MULTI_PAYLOAD_QUEUE, | ||
payload.toString()); | ||
} | ||
|
||
@RabbitListener(queues = "multi-payload-queue") | ||
@RabbitListener(queues = AmqpConstants.QUEUE_MULTI_PAYLOAD_QUEUE) | ||
public void bindingsBeanExample(ExamplePayloadDto payload) { | ||
log.info("Received new message in multi-payload-queue (ExamplePayloadDto): {}", payload.toString()); | ||
log.info( | ||
"Received new message in {} (ExamplePayloadDto): {}", | ||
AmqpConstants.QUEUE_MULTI_PAYLOAD_QUEUE, | ||
payload.toString()); | ||
} | ||
|
||
@RabbitListener( | ||
autoStartup = "false", | ||
queuesToDeclare = @Queue(name = AmqpConstants.QUEUE_CREATE, autoDelete = "false", durable = "true")) | ||
public void queuesToDeclareCreate(Message message, @Payload GenericPayloadDto<String> payload) { | ||
log.info( | ||
"Received new message {} in {} (GenericPayloadDto<String>): {}", | ||
message, | ||
AmqpConstants.QUEUE_CREATE, | ||
payload.toString()); | ||
} | ||
|
||
@RabbitListener( | ||
autoStartup = "false", | ||
queuesToDeclare = @Queue(name = AmqpConstants.QUEUE_DELETE, autoDelete = "false", durable = "true")) | ||
public void queuesToDeclareDelete(Message message, @Payload GenericPayloadDto<Long> payload) { | ||
log.info( | ||
"Received new message {} in {} (GenericPayloadDto<Long>): {}", | ||
message, | ||
AmqpConstants.QUEUE_DELETE, | ||
payload.toString()); | ||
} | ||
|
||
@RabbitListener( | ||
autoStartup = "false", | ||
bindings = | ||
@QueueBinding( | ||
exchange = | ||
@Exchange( | ||
name = AmqpConstants.EXCHANGE_CRUD_TOPIC_EXCHANGE_1, | ||
type = ExchangeTypes.TOPIC), | ||
key = AmqpConstants.ROUTING_KEY_ALL_MESSAGES, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using "#" routing key |
||
value = @Queue(name = AmqpConstants.QUEUE_UPDATE, durable = "true", autoDelete = "false"))) | ||
public void bindingsUpdate(Message message, @Payload GenericPayloadDto<ExamplePayloadDto> payload) { | ||
log.info( | ||
"Received new message {} in {} (GenericPayloadDto<ExamplePayloadDto>): {}", | ||
message, | ||
AmqpConstants.QUEUE_UPDATE, | ||
payload.toString()); | ||
} | ||
|
||
@RabbitListener( | ||
autoStartup = "false", | ||
bindings = | ||
@QueueBinding( | ||
exchange = | ||
@Exchange( | ||
name = AmqpConstants.EXCHANGE_CRUD_TOPIC_EXCHANGE_2, | ||
type = ExchangeTypes.TOPIC), | ||
key = AmqpConstants.ROUTING_KEY_ALL_MESSAGES, | ||
value = @Queue(name = AmqpConstants.QUEUE_READ, durable = "true", autoDelete = "false"))) | ||
public void bindingsRead(Message message, @Payload ExamplePayloadDto payload) { | ||
log.info( | ||
"Received new message {} in {} (ExamplePayloadDto): {}", | ||
message, | ||
AmqpConstants.QUEUE_UPDATE, | ||
payload.toString()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...amqp-example/src/main/java/io/github/springwolf/examples/amqp/dtos/GenericPayloadDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.examples.amqp.dtos; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
@Schema(description = "Generic payload model") | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class GenericPayloadDto<T> { | ||
|
||
@Schema(description = "Generic Payload field", requiredMode = REQUIRED) | ||
private T genericValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add YAML to ease analysis / investigation