我有一个时髦的脚本,我正在尝试开始;它的工作是读取一个消息队列,然后将消息重新排队到我们正在投入使用的一组新的 MQ 中。
这是代码:
@Grab(group='org.apache.camel', module='camel-core', version='2.11.0')
@Grab(group='org.apache.activemq', module='activemq-core', version='5.7.0')
@Grab(group='org.apache.activemq', module='activemq-camel', version='5.8.0')
@Grab(group='ch.qos.logback', module='logback-classic', version='1.0.13')
import org.apache.activemq.camel.component.ActiveMQComponent
import org.apache.activemq.ActiveMQConnectionFactory
import org.apache.camel.CamelContext
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
class CopyFromOneServerToAnother extends RouteBuilder{
public static void main(String[] args) {
final CamelContext camelContext = new DefaultCamelContext();
camelContext.addComponent("jms-01", ActiveMQComponent.activeMQComponent("tcp://mq01:61616"));
try {
// Add the routes defined below to the camel context
camelContext.addRoutes(new CopyFromOneServerToAnother());
camelContext.start();
Thread.sleep(10000000);
}
catch (final Exception e) {
e.printStackTrace();
}
finally {
try {
camelContext.stop();
}
catch (final Exception e) {
e.printStackTrace();
}
}
}
@Override
public void configure() throws Exception {
/// The name of the AMQ instance and queue where message will be taken from
from("jms-01:TEST-1")
.log("Processed")
// Final resting point for each message.
.to("jms-01:TEST-3")
.end();
}
}
因此,这是对源和目标使用相同的代理,但使用不同的队列。
这会读取消息,但是在尝试写入消息时会引发异常:
15:15:31.548 [Camel (camel-1) thread #0 - JmsConsumer[TEST-1]] INFO route1 - Processed
15:15:31.548 [Camel (camel-1) thread #0 - JmsConsumer[TEST-1]] DEBUG o.a.camel.processor.SendProcessor - >>>> Endpoint[jms-01://TEST-3] Exchange[JmsMessage[JmsMessageID: ID:mq01.dummycorp.corp-60083-1370438794752-5:131:1:1:1]]
15:15:31.594 [Camel (camel-1) thread #0 - JmsConsumer[TEST-1]] DEBUG o.a.c.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID:mq01.dummycorp.corp-60083-1370438794752-5:131:1:1:1 on ExchangeId: ID-ukm038662-local-53821-1370441730008-0-10). On delivery attempt: 0 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[JmsMessage[JmsMessageID: ID:mq01.dummycorp.corp-60083-1370438794752-5:131:1:1:1]]
15:15:31.595 [Camel (camel-1) thread #0 - JmsConsumer[TEST-1]] ERROR o.a.c.processor.DefaultErrorHandler - Failed delivery for (MessageId: ID:mq01.dummycorp.corp-60083-1370438794752-5:131:1:1:1 on ExchangeId: ID-ukm038662-local-53821-1370441730008-0-10). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[JmsMessage[JmsMessageID: ID:mq01.dummycorp.corp-60083-1370438794752-5:131:1:1:1]]
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[JmsMessage[JmsMessageID: ID:mq01.dummycorp.corp-60083-1370438794752-5:131:1:1:1]]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1354) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.impl.DefaultExchange.setException(DefaultExchange.java:272) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:137) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.interceptor.BacklogTracerInterceptor.process(BacklogTracerInterceptor.java:84) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91) ~[camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:390) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:335) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:117) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86) [camel-core-2.11.0.jar:2.11.0]
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:104) [camel-jms-2.10.3.jar:2.10.3]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:326) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:264) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1071) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1063) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960) [spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_21]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_21]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_21]
Caused by: java.lang.NoSuchMethodError: org.apache.camel.util.ObjectHelper.notNull(Ljava/lang/Object;Ljava/lang/String;)V
at org.apache.camel.component.jms.JmsBinding.makeJmsMessage(JmsBinding.java:285) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.component.jms.JmsProducer$2.createMessage(JmsProducer.java:270) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.doSendToDestination(JmsConfiguration.java:216) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.access$100(JmsConfiguration.java:159) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate$1.doInJms(JmsConfiguration.java:173) ~[camel-jms-2.10.3.jar:2.10.3]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:466) ~[spring-jms-3.1.3.RELEASE.jar:3.1.3.RELEASE]
at org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send(JmsConfiguration.java:170) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:402) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.component.jms.JmsProducer.processInOnly(JmsProducer.java:356) ~[camel-jms-2.10.3.jar:2.10.3]
at org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:132) ~[camel-jms-2.10.3.jar:2.10.3]
... 49 common frames omitted