Akka Camel - JMS messages lost - should wait for initialization of Camel? -
my experimental application quite simple, trying can done actors , akka.
after jvm start, creates actor scheme couple of plain actors, jms consumer (akka.camel.consumer) , jms producer (akka.camel.producer). sends couple of messages between actors , jms producer -> jms server -> jms consumer. talks via jms service.
from time time experiencing weird behaviour: seemed from time time, first of messages supposed sent jms server somehow lost. looking @ application logs, see applications trying send message never received jms server. (for each run have start jvm&application again).
akka camel documentation mentions it's possible components may not initialized @ begining: "some camel components can take while startup, , in cases might want know when endpoints activated , ready used."
i tried implement next wait camel initialization
val scheme = 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 help issue. (although, when removing step now, i'm not able recreate issue more... :/).
my question whether right way ensure components initialized?
should use
val future = camel.activationfuturefor(actor)(timeout = 10 seconds, executor = system.dispatcher) await.result(future, 10 seconds) for each akka.camel.producer , akka.camel.consumer actor sure initialized properly?
is should do, or else should done well? documentation not clean on , it's not easy test issue happening occasionaly...
you need initialize camel jms component , producer before sending 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 apache-camel akka
No comments:
Post a Comment