Spring Framework 6.1+ introduces the modern JmsClient API, providing a fluent, type-safe approach to JMS messaging with Apache ActiveMQ Artemis.
The new JmsClient API offers a modern alternative to JmsTemplate with a fluent, self-documenting approach,
automatic type conversion, and flexible QoS configuration. This demo showcases 7 essential messaging patterns
through an order management system.
- Basic Send: Fire-and-forget message delivery
- Quality of Service (QoS): TTL, priority, and delivery delays
- Custom Headers: Message metadata for routing and filtering
- Synchronous Receive: Pull messages with configurable timeout
- Receive and Convert: Type-safe message retrieval
- Request-Reply: RPC-style synchronous communication
- Reusable Operation Handle: Performance optimization through preconfiguration
https://github.com/danvega/jms-orders
https://www.danvega.dev/blog/jms-client
@Service
public class OrderMessagingService {
private final JmsClient jmsClient;
public OrderMessagingService(JmsClient jmsClient) {
this.jmsClient = jmsClient;
}
public void sendOrder(Order order) {
jmsClient.send("orders.queue")
.withBody(order);
}
}public void sendPriorityOrder(Order order) {
jmsClient.send("orders.queue")
.withPriority(9)
.withTimeToLive(Duration.ofMinutes(5))
.withBody(order);
}public OrderConfirmation processOrder(Order order) {
return jmsClient.requestAndReceive("orders.queue")
.withBody(order)
.convertTo(OrderConfirmation.class);
}@Component
public class OrderConsumer {
@JmsListener(destination = "orders.queue")
public void processOrder(Order order) {
// Process the order
}
}docker-compose up -d # Start ActiveMQ Artemis
./mvnw spring-boot:run # Run applicationAccess ActiveMQ Console: http://localhost:8161 (admin/admin)