与Akka Camel的集成测试

与Akka Camel的集成测试,akka,Akka,我开始了一个新的akka项目,但在akka camel集成测试方面遇到了问题 因此,我有一个消费者参与者,正在尝试测试它是否正在接收我发送的消息 这是测试 @Test public void testConsumer() { final String testXml = "<user>" + "<firstName>First</firstName>" + "<lastName>Last&l

我开始了一个新的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);

    }};
}
@测试
公共无效测试消费者(){
最后一个字符串testXml=“”+
“第一”+
“最后”+
"";
新的JavaTestKit(_系统){{
最终JavaTestKit探针=新JavaTestKit(_系统);
最终ActorRef subject2=_system.actorOf(Consumer.mkProps(probe.getRef(),端点,“testConsumerActor”);
camel.template().sendBody(端点,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]
15:15:02.442[驼峰(测试cdr)线程#0-seda://testRecords]警告o.a.c.component.seda.seda消费者-错误处理交换。交换[消息:FirstLast]。原因:[akka.camel.ActorNotRegisteredException-演员[akka://test-cdr/user/$a]不存在]
akka.camel.ActorNotRegisteredException:演员[akka://test-cdr/user/$a]不存在 在akka.camel.internal.component.ActorProducer$$anonfun$actorFor$1.apply(ActorComponent.scala:182)~[akka-camel_2.10-2.2.3.jar:na] 在akka.camel.internal.component.ActorProducer$$anonfun$actorFor$1.apply(ActorComponent.scala:182)~[akka-camel_2.10-2.2.3.jar:na] 在scala.Option.getOrElse(Option.scala:120)~[scala-library-2.10.3.jar:na] 在akka.camel.internal.component.ActorProducer.actorFor(ActorComponent.scala:182)~[akka-camel_2.10-2.2.3.jar:na]

当我通过测试进行调试时,我注意到在调用消费者的构造函数之前,camel正在发送消息。我如何防止这种情况?还是我遗漏了什么


SD

我对Akka Camel有问题,这似乎是Camel初始化的问题。在发送消息之前,我必须等待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()); 
actorrefproducer=system.actorOf(新道具(SimpleProducer.class),“SimpleProducer”);
Timeout Timeout=新超时(Duration.create(15秒));
Future activationFuture=camel.activationFutureFor(producer,timeout,system.dispatcher());
activationFuture.onComplete(新的onComplete(){
@凌驾
未完成的公共无效(可丢弃的arg0、ActorRef arg1)
扔掉的{
制作人。告诉(“第一!!”;
}
},system.dispatcher());
您是否在测试中执行任何类型的驼峰初始化?如果没有,添加类似的内容可能会有所帮助