我开始了一个新的akka项目,在akka-camel集成测试中遇到了一个问题。
因此,我有一个消费者角色,正在尝试测试它是否正在接收我发送的消息
下面是测试结果
@Test
public void testConsumer() {
final String testXml = "<user>" +
"<firstName>First</firstName>" +
"<lastName>Last</lastName>" +
"</user>";
new JavaTestKit(_system) {{
final JavaTestKit probe = new JavaTestKit(_system);
final ActorRef subject2 = _system.actorOf(Consumer.mkProps(probe.getRef(), endPoint, "testConsumerActor"));
camel.template().sendBody(endPoint, testXml);
}};
}测试失败,出现以下异常
15:15:02.442 [Camel (test-cdr) thread #0 - seda://testRecords] WARN o.a.c.component.seda.SedaConsumer - Error processing exchange. Exchange[Message: <user><firstName>First</firstName><lastName>Last</lastName></user>]. Caused by: [akka.camel.ActorNotRegisteredException - Actor [akka://test-cdr/user/$a] doesn't exist]用户:角色akka:// akka.camel.internal.component.ActorProducer$$anonfun$actorFor$1.apply(ActorComponent.scala:182) -cdr/user/$a不存在于akka.camel.internal.component.ActorProducer$$anonfun$actorFor$1.apply(ActorComponent.scala:182) ~akka-camel_2.10-2.2.3.jar:na at scala.Option.getOrElse ~akka-camel_2.10-2.2.3.jar:na at scala.Option.getOrElse(Option.scala:120) ~scala-akka.camel.ActorNotRegisteredException-2.10akka.camel.internal.component.ActorProducer.actorFor(ActorComponent.scala:182)上的camel~akka- .3.jar:na _2.10-2.2.3.jar:na
当我调试完我的测试时,我注意到在我的消费者的构造函数被调用之前,camel正在发送消息。我如何防止这种情况发生?还是我错过了什么?
标清
发布于 2014-02-28 04:28:10
我遇到了Akka-Camel的问题,这似乎是Camel初始化的问题。我必须等待Camel初始化,然后才能发送消息。
它是用Akka Camel - JMS messages lost - should wait for initialization of Camel?描述的
用于Camel初始化的Java版本为:
ActorRef producer = system.actorOf(new Props(SimpleProducer.class), "simpleproducer");
Timeout timeout = new Timeout(Duration.create(15, SECONDS));
Future<ActorRef> activationFuture = camel.activationFutureFor(producer,timeout, system.dispatcher());
activationFuture.onComplete(new OnComplete<ActorRef>() {
@Override
public void onComplete(Throwable arg0, ActorRef arg1)
throws Throwable {
producer.tell("First!!");
}
},system.dispatcher()); 您是否在测试中执行任何类型的Camel初始化?如果没有,添加类似这样的内容可能会有所帮助。
https://stackoverflow.com/questions/22053736
复制相似问题