Annotation Type MessageListener
Receives the messages of a destination: the method runs once per message, on a consumer thread of the server, and the message is acknowledged when it returns.
@Component
public class Shipping {
@MessageListener(value = "orders.placed", group = "shipping", concurrency = 4)
public void placed(Order order) { ... }
}
The method takes one parameter: the payload, read as JSON by a codec the
build generates for its type -- or a String, a byte[], or the whole
Message. A method that throws has the
message delivered again after a backoff, and after
cn1.messaging.retry.max-attempts deliveries it goes to
<destination>.dlq. Delivery is at least once, so a listener should be
safe to run twice for one message.
The build finds every listener and writes the code that subscribes it when
the server starts and stops it when the server stops; there is no
reflection. A destination may name a setting, ${orders.topic}, which is
read from the configuration when the server starts.
-
Element Details
-
value
-
destinations
-
group
String groupThe consumer group; subscriptions of one group share the messages, and each group gets every one. Empty meansspring.application.name, ordefaultwithout one.- Default:
""
-
concurrency
int concurrencyConsumer threads.- Default:
1
-