简体   繁体   中英

Camel RejectedExecutionException on sending to seda queue

My code looks as follows:

static ProducerTemplate producer = null;
...
public void process(Exchange exchange) {
    if (producer == null) {
        producer = exchange.getContext().createProducerTemplate();
    }

    for (Message msg : messages){
        Map<String, Object> headers = Maps.newHashMap();
        headers.put("DisplayMessages", true);
        producer.sendBodyAndHeaders("seda:aggregate-messages?blockWhenFull=true&size=500", msg, headers);
    }
}

I'm getting a RejectedExecutionException null thrown on the line producer.sendBody... .

From what I can tell this is normally caused by trying to send multiple asynchronous exchanges down a non asynchronous route. But isn't SEDA asynchronous ?

You need to code your processors as thread-safe. And the code above is not thread safe.

You should initialize and cleanup logic in the doStart and doStop methods according to the lifecycle

There you can setup the producer template once, and then your processor can become thread-safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM