Я хочу отправить сообщение в очередь JMS с Camel. Тело - это байтовый массив, и я ожидаю, что Camel преобразует его в javax.jms.BytesMessage
и отправляет без проблем, но я получаю следующее предупреждение.
Warning
[org.apache.camel.component.jms.JmsBinding] (Camel (camel) thread #0 -
JmsConsumer[devrechTransactionsQueue@z4smq_4001)
Cannot determine specific JmsMessage type to use from body class.
Will use generic JmsMessage. Body class: org.apache.camel.impl.DefaultMessage.
If you want to send a POJO then your class might need to implement java.io.Serializable,
or you can force a specific type by setting the jmsMessageType option on the JMS endpoint.
Если я пытаюсь установить тип вручную (exchange.getIn().setHeader("CamelJmsMessageType", JmsMessageType.Bytes);
), я получаю исключение NullPointerException.
Exception
[org.apache.camel.processor.DefaultErrorHandler] (Camel (camel) thread #0 - JmsConsumer[devrechTransactionsQueue@z4smq_4001) Failed delivery for exchangeId: ID-madansportapp02-5
1560-1313509081079-0-1. Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
java.lang.NullPointerException
at com.swiftmq.tools.util.DataByteArrayOutputStream.write(Unknown Source)
at com.swiftmq.jms.BytesMessageImpl.writeBytes(Unknown Source)
at org.apache.camel.component.jms.JmsBinding.createJmsMessageForType(JmsBinding.java:506)
at org.apache.camel.component.jms.JmsBinding.createJmsMessage(JmsBinding.java:443)
at org.apache.camel.component.jms.JmsBinding.makeJmsMessage(JmsBinding.java:267)
at org.apache.camel.component.jms.JmsProducer$2.createMessage(JmsProducer.java:225)
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.doSendToDestination(JmsConfiguration.java:198)
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.access$100(JmsConfiguration.java:141)
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate$3.doInJms(JmsConfiguration.java:175)
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:466)
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:172)
at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:347)
at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:303)
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:101)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:114)
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:286)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:109)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:99)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:318)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)
at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:305)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:116)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:79)
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:102)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78)
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:69)
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:104)
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:85)
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:91)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560)
...
Code
public class MessageTranslator implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
RechargeType transaction = (RechargeType) exchange.getIn().getBody();
exchange.getIn().setBody(createMessage(transaction));
}
private Message createMessage(RechargeType transaction) throws DataException, IOException {
Message message = new DefaultMessage(); // camel message
Request request = new Request(transaction); // our request
final byte[] serializedPayload = RequestSerializationHelper.getSerializedPayload(request); // serialized request
message.setBody(serializedPayload);
return message;
}
}