首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Akka-Camel进行集成测试

使用Akka-Camel进行集成测试
EN

Stack Overflow用户
提问于 2014-02-27 05:28:09
回答 1查看 615关注 0票数 1

我开始了一个新的akka项目,在akka-camel集成测试中遇到了一个问题。

因此,我有一个消费者角色,正在尝试测试它是否正在接收我发送的消息

下面是测试结果

代码语言:javascript
复制
@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);

    }};
}

测试失败,出现以下异常

代码语言:javascript
复制
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正在发送消息。我如何防止这种情况发生?还是我错过了什么?

标清

EN

回答 1

Stack Overflow用户

发布于 2014-02-28 04:28:10

我遇到了Akka-Camel的问题,这似乎是Camel初始化的问题。我必须等待Camel初始化,然后才能发送消息。

它是用Akka Camel - JMS messages lost - should wait for initialization of Camel?描述的

用于Camel初始化的Java版本为:

代码语言:javascript
复制
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初始化?如果没有,添加类似这样的内容可能会有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22053736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档