Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm trying to write JMS Consumer using Akka-Camel.

For now, I'm using FFMQ as JMS server. I want to listen on JMS queue myqueue.

Creating JMS consumer actor is quite straightforward:

import akka.camel.{CamelMessage, Consumer}
import akka.event.Logging

class JMSConsumer extends Consumer {
  val log = Logging(context.system, this)
  def endpointUri = "jms:queue:myqueue"

  def receive = {
    case m: CamelMessage => {
      log.info(s"JMS Received $m")
    case other => {
      log.info(s"JMS Received unknown message type : $other")

But I'm struggling with configuration of jms component.

In order to connect to JMS server, I need to specify few properties as specified in FFMQ documentation.

So far I only managed to do this by specifying parameters using some Camel internals.

import akka.actor.{Props, ActorSystem}
import akka.camel.CamelExtension
import org.apache.camel.component.jms.{JmsConfiguration, JmsComponent}
import java.util.Hashtable
import javax.naming.{InitialContext, Context}
import net.timewalker.ffmq3.FFMQConstants
import javax.jms.{Session, ConnectionFactory}

object MainApp extends App {
  val system = ActorSystem("TestSystem")

  def jmsConnectionFactory() : ConnectionFactory = {
    val env = new Hashtable[String, String]();
    env.put(Context.PROVIDER_URL, "tcp://localhost:10002");
    val context: Context = new InitialContext(env);


  val jmsConfiguration = new JmsConfiguration(jmsConnectionFactory)

  val jmsComponent = new JmsComponent(jmsConfiguration)

  val camel = CamelExtension(system)
  camel.context.addComponent("jms", jmsComponent)
  val jmsConsumer = system.actorOf(Props[JMSConsumer], name="myqueueConsumer")

I'm wondering if this is the way how akka-camel is intended to be used.

It seems that I'm just putting random things together, possibly going into too low-level detail when doing JNDI lookup myself?

Unfortunately, akka-camel documentation doesn't go into details here.

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.