Я использую многоадресную рассылку для фильтрации дубликатов.Я создал свою AggregationStrategy
package model;
import org.apache.camel.Exchange;
import org.apache.camel.processor.aggregate.AggregationStrategy;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;
public class CentersAggregationStrategy implements AggregationStrategy {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
try {
if (oldExchange != null) {
return null;
}
Centers centers;
if (newExchange.getIn().getBody(Centers.class) != null) {
centers = newExchange.getIn().getBody(Centers.class);
} else {
centers = unemarshalCenters(newExchange.getIn().getBody(String.class));
}
newExchange.getIn().setBody(centers);
return newExchange;
} catch (JAXBException ex) {
ex.printStackTrace();
return newExchange;
}
}
private Centers unemarshalCenters(String source) throws JAXBException {
return (Centers) JAXBContext.newInstance(Centers.class)
.createUnmarshaller().unmarshal(new StreamSource(new StringReader(source)));
}
}
И я использую ее в своей многоадресной рассылке:
RouteBuilder routeBuilder = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:aggregate")
.setHeader(Exchange.HTTP_PATH, simple("animals"))
.multicast(new CentersAggregationStrategy())
.parallelProcessing()
.enrich(SERVICE_URL + FIRST_PORT)
.enrich(SERVICE_URL + SECOND_PORT)
.enrich(SERVICE_URL + THIRD_PORT)
.end()
.to("direct:aggregate-file");
from("direct:aggregate-file")
.to("file:aggregate-output");
}
};
Вот моя проблема: когда я пытаюсь запустить этот код, он выдает эту ошибку:
Exception in thread "main" org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[ID-inf-50-7-1554218530628-0-1]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1846)
at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:713)
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:515)
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:511)
at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:163)
at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:168)
at eip.AgregateProducerConsumer.main(AgregateProducerConsumer.java:61)
Caused by: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: aggregate-output/ID-inf-50-7-1554218530628-0-5
at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:354)
at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:305)
at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:169)
at org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:80)
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
Но это прекрасно работает, когда я просто заменяю .to ("direct: aggregate-file") на журнал ... Поэтому я ищу способ записать результат в файл