Skip to content

Instantly share code, notes, and snippets.

@yoeluk
Forked from cjjavellana/Jms.scala
Created March 3, 2016 04:41
Show Gist options
  • Save yoeluk/266cc1380840d732fa13 to your computer and use it in GitHub Desktop.
Save yoeluk/266cc1380840d732fa13 to your computer and use it in GitHub Desktop.
Scala Akka Camel Weblogic JMS Sample
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment