|
Akka/Scala example source code file (PublishSubscribe.scala)
The PublishSubscribe.scala Akka example source codepackage docs.camel object PublishSubscribe { //#PubSub import akka.actor.{ Actor, ActorRef, ActorSystem, Props } import akka.camel.{ Producer, CamelMessage, Consumer } class Subscriber(name: String, uri: String) extends Actor with Consumer { def endpointUri = uri def receive = { case msg: CamelMessage => println("%s received: %s" format (name, msg.body)) } } class Publisher(name: String, uri: String) extends Actor with Producer { def endpointUri = uri // one-way communication with JMS override def oneway = true } class PublisherBridge(uri: String, publisher: ActorRef) extends Actor with Consumer { def endpointUri = uri def receive = { case msg: CamelMessage => { publisher ! msg.bodyAs[String] sender() ! ("message published") } } } // Add below to a Boot class // Setup publish/subscribe example val system = ActorSystem("some-system") val jmsUri = "jms:topic:test" val jmsSubscriber1 = system.actorOf(Props(classOf[Subscriber], "jms-subscriber-1", jmsUri)) val jmsSubscriber2 = system.actorOf(Props(classOf[Subscriber], "jms-subscriber-2", jmsUri)) val jmsPublisher = system.actorOf(Props(classOf[Publisher], "jms-publisher", jmsUri)) val jmsPublisherBridge = system.actorOf(Props(classOf[PublisherBridge], "jetty:http://0.0.0.0:8877/camel/pub/jms", jmsPublisher)) //#PubSub } Other Akka source code examplesHere is a short list of links related to this Akka PublishSubscribe.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.