阿卡骆驼 - JMS消息丢失 - 应等待骆驼的初始化? [英] Akka Camel - JMS messages lost - should wait for initialization of Camel?

查看:200
本文介绍了阿卡骆驼 - JMS消息丢失 - 应等待骆驼的初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的实验应用程序是非常简单的,想什么可以与演员和阿卡完成。

My experimental application is quite simple, trying what can be done with Actors and Akka.

JVM启动后,它创建的演员系统普通情侣的演员,JMS消费者(akka.camel.Consumer)和JMS生产者(akka.camel.Producer)。它发出夫妇参与者之间的消息,也JMS生产者 - > JMS服务器 - > JMS消费者。它主要通过JMS服务谈话本身。

After JVM start, it creates actor system with couple of plain actors, JMS consumer (akka.camel.Consumer) and JMS producer (akka.camel.Producer). It sends couple of messages between actors and also JMS producer -> JMS server -> JMS consumer. It basically talks to itself via JMS service.

不时我正经历着怪异的行为:它似乎是的不时,首先它应该在哪里被发送到JMS服务器的消息在某种程度上失去了的。通过观察我的应用程序日志,我可以看到,应用程序试图发送邮件,但它永远不会被JMS服务器接收。 (对于每一个跑,我要开始JVM和放大器;再次申请)。

From time to time I was experiencing weird behaviour: it seemed that from time to time, first of messages which where supposed to be sent to JMS server was somehow lost. By looking at my application logs, I could see that applications is trying to send the message but it was never received by JMS server. (For each run I have to start JVM&Application again).

阿卡骆驼文档提到,这是可能的某些组件可能不会在开始时被完全初始化:有些驼组件可能需要一段时间来启动,在某些情况下,你可能想知道当端点被激活并准备使用

Akka Camel Documentation mentions that it's possible that some components may not be fully initialized at the begining: "Some Camel components can take a while to startup, and in some cases you might want to know when the endpoints are activated and ready to be used."

我试图执行下面等待初始化骆驼

I tried to implement following to wait for Camel initialization

val system = ActorSystem("actor-system")
val camel = CamelExtension(system)

val jmsConsumer = system.actorOf(Props[JMSConsumer])
val activationFuture = camel.activationFutureFor(jmsConsumer)(timeout = 10 seconds, executor = system.dispatcher)
val result = Await.result(activationFuture,10 seconds)

这似乎帮助解决这个问题。 (虽然,现在去掉这一步的时候,我不能重新创建此问题的任何更多...:/)。

which seems to help with this issue. (Although, when removing this step now, I'm not able to recreate this issue any more... :/).

我的问题是,这是否是为了确保所有组件正确的方法是完全初始化?

My question is whether this is correct way to ensure all components are fully initialized?

我应该用

val future = camel.activationFutureFor(actor)(timeout = 10 seconds, executor = system.dispatcher)
Await.result(future, 10 seconds)

每个akka.camel.Producer和akka.camel.Consumer演员的,以确保一切正确初始化?

for each akka.camel.Producer and akka.camel.Consumer actor to be sure that everything is initialized properly?

时,所有我应该做的,还是其他什么东西应该做的呢?文档不干净上,它不容易测试的问题是发生只有occasionaly ...

Is that all I should to do, or something else should be done as well? Documentation is not clean on that and it's not easy to test as issue was happening only occasionaly...

推荐答案

您需要发送任何消息之前初始化JMS骆驼组成部分,并监制。

You need to initialize the camel JMS component and also Producer before sending any messages.

import static java.util.concurrent.TimeUnit.SECONDS;

import scala.concurrent.Future;

import scala.concurrent.duration.Duration;

import akka.dispatch.OnComplete;

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()); 

这篇关于阿卡骆驼 - JMS消息丢失 - 应等待骆驼的初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆