如何在骆驼处理器中调用 unmarshal()?

How to call unmarshal() in camel processor?

骆驼路线:

from(source)          
    .idempotentConsumer(simple("${in.header.CamelFilePath}"), redisIdempotentRepository)
    .process(pgpDecryptionProcessor)
    .to(destination);

PGPDecryptionProcessor:

public class PGPDecryptionProcessor implements Processor {

  @Autowired
  private PGPEncryptionManager pgpEncryptionManager;

  @Override
  public void process(Exchange exchange) throws Exception {
     //do something to check whether it is encrypted 
     //get corrsponding dataformat for decryption
     processDefinition.unmarshal(dataFormat);  //How do i get processDefinition here
    }
  }
} 

我需要打电话给ProcessDefinition.unmarshal(dataformat)。如何在 process 方法中获取 ProcessDefinition 对象?

您可以使用 ExchangeExchange.getIn().getBody(InputStream.class) 作为另一个参数直接调用数据格式的解组:

dataformat.unmarshal(exchange, exachange.getIn().getBody(InputStream.class));

您不需要调用 ProcessDefinition.unmarshal()ProcessDefinition 仅定义要​​使用的数据格式,最后当您的消息到达时,Dataformat.unmarshal() 方法被 ExchangeBody InputStream 调用。