[ https://issues.apache.org/jira/browse/CAMEL-12638?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16543301#comment-16543301 ]
Willem Jiang commented on CAMEL-12638: -------------------------------------- OK, I saw the java doc. Normally the template send, request method are thread safe, but withBody() is not thread safe, we can fix it by declare the body as thread local , but there are some other settings such as endpoint, processorSupplier which are not thread safe. So I just add a comment that we need treat FluentProducerTemplate as a Builder. {code:java} public class DefaultFluentProducerTemplate extends ServiceSupport implements FluentProducerTemplate { private final CamelContext context; private final ClassValue<ConvertBodyProcessor> resultProcessors; private Map<String, Object> headers; private Object body; private Optional<Consumer<ProducerTemplate>> templateCustomizer; private Optional<Supplier<Exchange>> exchangeSupplier; private Optional<Supplier<Processor>> processorSupplier; private Optional<Endpoint> endpoint; private Optional<Endpoint> defaultEndpoint; private int maximumCacheSize; private boolean eventNotifierEnabled; private volatile ProducerTemplate template; ...{code} > DefaultFluentProducerTemplate is not thread safe > ------------------------------------------------ > > Key: CAMEL-12638 > URL: https://issues.apache.org/jira/browse/CAMEL-12638 > Project: Camel > Issue Type: Bug > Components: camel-core > Affects Versions: 2.20.2 > Reporter: Lukasz > Priority: Major > Attachments: image-2018-07-12-17-58-09-225.png > > > I think we have rediscovered the CAMEL-10820 bug. A body of one request gets > replaced with a body of proceeding request, in our case we use *request()* > method instead of *asyncSend()*. > We use camel together with spring-boot. Consider following code: > > {code:java} > @Service > public class UseCamelService { > private FluentProducerTemplate producer; > @Autowired > public UseCamelService(FluentProducerTemplate producer) { > this.producer = producer; > } > public String getValueFromCamel(String body) { > return producer.to("route").withBody(body).request(String.class); > } > } > {code} > If *UseCamelService.getValueFromCamel()* gets called from two different > threads it is possible for the latter one to override the body of the first > one. -- This message was sent by Atlassian JIRA (v7.6.3#76005)