Reputation: 185
I have a Camel route which converts JSON to an object and passes it on to a processor class. Code is below. This ActiveMQ consumer is not acknowledging some messages, causing the topic to get backed up. The code does not explicitly set acknowledgement mode but a breakpoint shows these values -
acknowledgementMode = -1 acknowledgementModeName = null
What should be changed to ensure acknowledgements are sent on both successful processing and when an exception occurs inside the processor class?
@Component
public class MyRoute extends RouteBuilder {
private String mySubscription;
private MyProcessor myProcessor;
public MyRoute(@Value("${my.topic}") String tripSubscription, MyProcessor myProcessor) {
this.mySubscription = mySubscription;
this.myProcessor = myProcessor;
}
@Override
public void configure() {
from(mySubscription)
.unmarshal().json(JsonLibrary.Jackson, MyDTO.class)
.bean(myProcessor, "process(${body})")
.end();
}
}
The processor class -
@Slf4j
@Component
@AllArgsConstructor
public class MyProcessor {
public void process(MyDTO dto) {
//code that throws exception
}
}
Upvotes: 0
Views: 2095
Reputation: 12748
Use handled(true)
on your onException()
route, and from pov of client, this message is consumed and exception eaten.
Upvotes: 0
Reputation: 320
Side note… looks like you’re not setting “tripSubscription” into and instance variable if that was your intent…
Upvotes: 1
Reputation: 7005
The Camel JMS component docs at Github says that the default acknowledge mode is AUTO_ ACKNOWLEDGE
.
However, the older docs at camel.apache.org says the default is -1
what corresponds to the value you see. Either the default was changed in a recent version or the new docs at Github are wrong.
The value -1
is somehow invalid because it is none of the defined modes.
Therefore you could give it a try to explicitly set acknowledgementModeName=AUTO_ACKNOWLEDGE
on your consumer.
Upvotes: 1