Akka Camel和ActiveMQ:如何设置交付模式

时间:2015-09-26 12:11:27

标签: scala akka activemq akka-camel

据我所知,默认情况下,ActiveMQ将传递模式设置为PERSISTENT ...因此,在使用Akka-Camel时,如何为特定主题设置传递模式为NON_PERSISTENT?以下是我的示例代码:

import akka.actor._
import akka.camel._
import org.apache.activemq.camel.component.ActiveMQComponent

case class MyMessage(body: String)

class MyProducer() extends Actor with Producer with Oneway {
  def endpointUri: String = "activemq:MyTopic"
}

class SimpleConsumer() extends Actor with Consumer {
  def endpointUri: String = "activemq:MyTopic"

  def receive = {
    case msg: CamelMessage => println(msg)
  }
}

object MyApp extends App {

  val actorSystem = ActorSystem("MyApp")
  val system = CamelExtension(actorSystem)

  system.context.addComponent(
     "activemq",
     ActiveMQComponent.activeMQComponent("nio://localhost:61616")
  )

  val consumer = actorSystem.actorOf(Props[MyConsumer])
  val producer = actorSystem.actorOf(Props[MyProducer])

  ...

  producer ! MyMessage("hello")

  ...

  actorSystem.shutdown()
}

1 个答案:

答案 0 :(得分:1)

在端点URI上设置options

"activemq:MyTopic?deliveryPersistent=false"
相关问题