Last active
August 29, 2016 08:59
-
-
Save cjjavellana/2b422e694e5acf253d22 to your computer and use it in GitHub Desktop.
Scala Akka Camel Weblogic JMS Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Properties | |
import org.apache.camel.component.jms.{ JmsComponent, JmsConfiguration } | |
import org.springframework.jms.support.destination.JndiDestinationResolver | |
import org.springframework.jndi.{ JndiObjectFactoryBean, JndiTemplate } | |
import akka.actor.{ ActorSystem, Props } | |
import akka.camel.CamelExtension | |
import javax.jms.ConnectionFactory | |
object ClientLauncher { | |
def main(args: Array[String]) { | |
val system = ActorSystem("system") | |
val camel = CamelExtension(system) | |
val camelContext = camel.context | |
camelContext.addComponent("jms", jmsComponent) | |
val actorRef = system.actorOf(Props[RequestMessageConsumer]) | |
val producer = system.actorOf(Props[ResponseMessageProducer]) | |
producer ! "Test" | |
} | |
def jndiTemplate: JndiTemplate = { | |
val jndiProperties = new Properties | |
jndiProperties.setProperty("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory") | |
jndiProperties.setProperty("java.naming.provider.url", "t3://localhost:7001") | |
val jndiTemplate = new JndiTemplate(jndiProperties) | |
jndiTemplate | |
} | |
def jndiDestinationResolver: JndiDestinationResolver = { | |
val jndiDestinationResolver = new JndiDestinationResolver | |
jndiDestinationResolver.setJndiTemplate(jndiTemplate) | |
jndiDestinationResolver | |
} | |
def connectionFactory: ConnectionFactory = { | |
val jndiObjectFactory = new JndiObjectFactoryBean | |
jndiObjectFactory.setJndiTemplate(jndiTemplate) | |
jndiObjectFactory.setJndiName("jms/connectionFactory") | |
jndiObjectFactory.afterPropertiesSet() | |
val jmsConnectionFactory = jndiObjectFactory.getObject.asInstanceOf[ConnectionFactory] | |
jmsConnectionFactory | |
} | |
def jmsConfiguration: JmsConfiguration = { | |
val jmsConfiguration = new JmsConfiguration | |
jmsConfiguration.setConnectionFactory(connectionFactory) | |
jmsConfiguration.setDestinationResolver(jndiDestinationResolver) | |
jmsConfiguration | |
} | |
def jmsComponent: JmsComponent = { | |
val jmsComponent = new JmsComponent(jmsConfiguration) | |
jmsComponent | |
} | |
} |
RequestMessageConsumer.scala
import akka.camel.{ Consumer, CamelMessage }
import akka.actor.ActorRef
class RequestMessageConsumer(producer: ActorRef) extends Consumer {
override def autoAck = false
def endpointUri = "jms:queue:someQueue"
def receive = {
case msg: CamelMessage => {
val message = msg.getBodyAs(classOf[Message], camel.context)
}
}
}
Message.scala
case class Message(v1: String, v2: String, v3: String, v4: String)
ResponseMessageProducer.scala
import akka.actor.Actor
import akka.camel.{ Producer, Oneway }
class ResponseMessageProducer extends Actor with Producer with Oneway {
def endpointUri = "jms:queue:someQueue"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I cannot resolve these two lines when i tried running this code locally
val actorRef = system.actorOf(Props[RequestMessageConsumer])
val producer = system.actorOf(Props[ResponseMessageProducer])
Error: ms.scala:22: not found: type RequestMessageConsumer
Any hint would be appreciated and thanks.