https://github.com/dashiodevs/aspect-amqp
🛠️ A lightweight library for handling AMQP messaging in Java with AOP (Aspect-Oriented Programming).
https://github.com/dashiodevs/aspect-amqp
amqp aop aspect-oriented-programming aspectj java rabbitmq spring
Last synced: 5 months ago
JSON representation
🛠️ A lightweight library for handling AMQP messaging in Java with AOP (Aspect-Oriented Programming).
- Host: GitHub
- URL: https://github.com/dashiodevs/aspect-amqp
- Owner: DashioDevs
- License: apache-2.0
- Created: 2025-01-17T13:14:34.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-22T23:46:33.000Z (5 months ago)
- Last Synced: 2025-01-23T00:27:16.603Z (5 months ago)
- Topics: amqp, aop, aspect-oriented-programming, aspectj, java, rabbitmq, spring
- Language: Java
- Homepage:
- Size: 127 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Message Aspect for RabbitMQ 🐇📤
This module provides a `MessageAspect` that allows automatic sending of messages to RabbitMQ after a method execution. It is based on **Spring AOP** and uses **Testcontainers** for integration tests with a real RabbitMQ instance.
---
## 📦 Installation
### Dependencies
To integrate the module into a Spring project, add the following dependencies to your `pom.xml` file:
```xml
org.springframework.boot
spring-boot-starter-amqp
org.springframework.boot
spring-boot-starter-aop
net.dashio
aspect-amqp
````
---
## 🛠️ Usage
### Create a @PublishMessage Annotation
Use the `@PublishMessage` annotation on a method to enable the RabbitMQ message sending process:
```java
@PublishMessage(
exchange = "your_exchange",
routingKey = "your_routing_key"
)
public YourReturnType yourMethod() {
return new YourReturnType();
}
```### Adding @MessageMapping
Define a `@MessageMapping` child annotation to specify how the message should be transformed:
```java
@PublishMessage(
exchange = "your_exchange",
routingKey = "your_routing_key",
mapping = @MessageMapping(function = "#value.name", value = "value")
)
public YourReturnType yourMethod() {
return new YourReturnType();
}
```### Fancy expressions
Somewhere you got:
```java
import java.util.UUID;public record User(UUID id, String name) {
//Your methods
}public class Utils {
public String concatUser(User user) {
return user.id + ":" + user.name;
}
}
``````java
@PublishMessage(
exchange = "your_exchange",
routingKey = "your_routing_key",
mapping = @MessageMapping(function = "T(your.package.Utils).concatUser(#value)", value = "value")
)
public YourReturnType yourMethod() {
return new YourReturnType();
}```
---
## 📖 How the MessageAspect Works- **`@PublishMessage`**: Used to mark methods that should send a message to RabbitMQ.
- **`@MessageMapping`**: Defines how data within the object should be processed for RabbitMQ message transfer.---
## 💡 Benefits
- **Automation**: No need to manually send messages to RabbitMQ.
- **Aspect-Oriented**: Use AOP (Aspect-Oriented Programming) to send messages after the method execution.---
## 🔧 Extendability
- Add custom **message transformations** by configuring the `@MessageMapping` function.
- Extend the aspect to add additional logic before or after the message processing.