问题
How Apache Camel Seda Component works?
回答1:
I did not find any question in your input. Therefore I guess you ask the ultimate question about Life, the Universe and Everything.
So, the answer is: 42 ;-)
回答2:
Let me explain you with the below code snippet
a. from("direct:startProcess")
b. .process(new TestProcessor())
c. .split(method(new BaseSplitter<Integer>()))
d. .parallelProcessing()
e. .to("seda:checkforCorrect");
f. from("seda:checkforCorrect?concurrentConsumers=25")
g. …...processing the message
Above Code has below Lines
Starting Point
Test Processor
Splitter
ParallelProcessing
Consumer
Producer
a) Starting Point for Demo
b) Test Processor Generating the List of Element (For Demo)
public class TestProcessor implements Processor {
private static final Logger LOGGER = Logger.getLogger(TestProcessor.class);
@Override
public void process(Exchange exchange) {
ArrayList list = new ArrayList();
for(int i=0; i<2000;i++) {
list.add(new Integer(i));
}
exchange.getIn().setBody(list);
exchange.setPattern(ExchangePattern.InOut);
}
}
c) Splitter Splitter splits List into individual messages
public class BaseSplitter<T> {
/** The logger instance. */
private static final Logger LOGGER = Logger.getLogger(BaseSplitter.class);
/**
* The default constuctor.
*/
public BaseSplitter() {
super();
}
/**
* The method to split the passed list to spawn multiple threads by the
* Camel.
*
* @param list
* the the list to split.
* @return the splitted list.
*/
public List<T> split(List<T> list) {
LOGGER.debug("Inside ConfigList");
return list;
}
}
d) Parallel Processing create default (10) number of threads which will handle individual messages generated by splitter
e) Producer Part This act as producer for checkforCorrect Queue of Seda component, So with above parallel processing part it will create default number of threads which act as producer to seda component queue
f) Consumer Part
In the code snippet below we are making threads (25) which act as consumer for checkforCorrect Queue
from("seda:checkforCorrect?concurrentConsumers=25")
.
To increase number of Producer Threads of seda component :- add the executorService as shown below
from("direct:startProcess")
.process(new TestProcessor())
.split(method(new BaseSplitter<Integer>()))
.parallelProcessing()
.executorService(Executors.newFixedThreadPool(20))
.to("seda:checkforCorrect");
来源:https://stackoverflow.com/questions/58863298/how-apache-camel-seda-component-works