How Apache camel SEDA Component works

两盒软妹~` 提交于 2019-12-24 18:19:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!