How do you create a message listener in Spring RabbitMQ?
Add spring-boot-starter-amqp, declare the queue and put @RabbitListener on a bean method. Includes JSON conversion, retries and dead-lettering.
2,887 posts about Java: questions with answers, tutorials and articles, newest first.
Add spring-boot-starter-amqp, declare the queue and put @RabbitListener on a bean method. Includes JSON conversion, retries and dead-lettering.
@EnableRabbit activates @RabbitListener processing in Spring AMQP. Boot applies it for you, so see when you need it and how to configure RabbitMQ.
Declare queues and bindings, send JSON with RabbitTemplate and consume with @RabbitListener, then add retries and dead-letter handling.
A message broker lets services communicate asynchronously. See how Spring integrates RabbitMQ, Kafka and STOMP, and how to choose between them.
ApplicationEventPublisher lets Spring beans publish events that listeners handle without direct coupling. See publishEvent, @EventListener and transactional events.
Inject ApplicationEventPublisher, call publishEvent with a record, and react with @EventListener. Covers transaction-bound and async listeners.
@TransactionalEventListener runs a Spring listener after a transaction commits or rolls back, so side effects happen only when data is saved. Phases and examples.
Add a @Version field so JPA detects concurrent updates, then handle OptimisticLockException with retries or a conflict response.
@Version enables optimistic locking in JPA. See how to use it with Spring Data repositories, retry on conflicts and pass the version through REST ETags.
Plain JPA offers only lifecycle callbacks. Learn to track creation and modification time and user with callbacks and Spring Data JPA auditing.
Learn how JPA @PrePersist and @PostPersist callbacks work: when they fire, how to set defaults and timestamps, entity listeners and common pitfalls.
JPA lifecycle callbacks run methods before or after an entity is persisted, updated, removed or loaded. Learn the seven annotations, listeners and their limits.
@EntityListeners links listener classes to JPA lifecycle events. See the callback signatures, execution order and rules for what callbacks may do.
Learn to call methods through the Java Reflection API, handle static, private and varargs cases, unwrap exceptions and know when MethodHandle is better.
Reflection is slower than direct calls due to lookups, boxing and lost inlining. Learn how to cache, use MethodHandle, and measure the real cost with JMH.
Get a Class object with a literal, getClass or Class.forName, then inspect its fields, methods, constructors and annotations with java.lang.reflect.
Reflection lets Java programs inspect and call classes, methods and fields at runtime. Learn its purpose, examples, performance cost and module limits.
What @Component does in Spring, how component scanning finds beans, how to inject them, and how it compares with @Service, @Repository and @Bean.
Put @PropertySource on a @Configuration class to add a properties file to the Spring Environment, then read values with @Value, Environment or @ConfigurationProperties.
ApplicationContextInitializer lets you customise the Spring context before beans are created. See where it fits, how to register it and alternatives.