【问题标题】:Integration testing with Akka-Camel使用 Akka-Camel 进行集成测试
【发布时间】:2014-02-28 04:28:10
【问题描述】:

我开始了一个新的 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.camel.ActorNotRegisteredException: Actor [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 正在发送消息。我该如何防止这种情况?还是我错过了什么?

标清

【问题讨论】:

    标签: akka


    【解决方案1】:

    我遇到了 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 初始化?如果没有,添加这样的内容可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 2019-12-17
      • 2015-12-28
      • 2020-05-26
      • 2018-01-02
      • 2021-02-03
      • 2015-06-14
      相关资源
      最近更新 更多