Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the event-driven consumer in Apache Camel delete the consumed messages?

I have a rest service that sends messages to my queue, and these are routed to file:

from("test-jms:queue:test.queue").to("file://test");

Also, I have an event-driven consumer on the endpoint. For now this only writes to the log if a message is consumed:

final Consumer consumer = endpoint.createConsumer(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            String message = exchange.getIn().getBody(String.class);

            LOG.info("Message processed: " + message);
        }
    });

This is all working fine. In the /test folder I am getting a new file for every message I recieve, and additionally the consumer creates a marker file appended with .camelLock. Using the readLock=none option prevents the consumer from making these marker files, as expected.

However, neither the message files nor the marker files are deleted after consumption. Am I perhaps missing something in my consumer implementation?

like image 281
Mimeshead Avatar asked Mar 19 '23 19:03

Mimeshead


1 Answers

When you manually create a consumer like that with an inlined processor, you need to manually done the UoW of the Exchange when you are done to trigger work that would delete/move the file etc.

exchange.getUnitOfWork().done(exchange);

You can also try wrapping your processor with the UnitOfWorkProducer that should do the done of the UnitOfWork for you.

like image 166
Claus Ibsen Avatar answered Apr 06 '23 04:04

Claus Ibsen