当前位置: 首页>>代码示例>>Scala>>正文


Scala BrokerService类代码示例

本文整理汇总了Scala中org.apache.activemq.broker.BrokerService的典型用法代码示例。如果您正苦于以下问题:Scala BrokerService类的具体用法?Scala BrokerService怎么用?Scala BrokerService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BrokerService类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: JmsSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.jms

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.testkit.TestKit
import org.apache.activemq.broker.BrokerService
import org.scalatest._
import org.scalatest.concurrent.ScalaFutures
import akka.testkit.SocketUtil

abstract class JmsSpec
    extends WordSpec
    with Matchers
    with BeforeAndAfterAll
    with BeforeAndAfterEach
    with ScalaFutures {

  implicit val system = ActorSystem(this.getClass.getSimpleName)
  implicit val materializer = ActorMaterializer()

  override protected def afterAll(): Unit =
    TestKit.shutdownActorSystem(system)

  def withServer(network: Boolean = true)(test: Context => Unit): Unit = {
    val broker = new BrokerService()
    val host: String = "localhost"
    val url = if (network) {
      val port = SocketUtil.temporaryServerAddress(host).getPort
      val serverUrl = s"tcp://$host:$port"
      broker.addConnector(serverUrl)
      serverUrl
    } else {
      s"vm://$host"
    }
    broker.setPersistent(false)
    broker.setBrokerName(host)
    broker.setUseJmx(false)
    broker.start()
    try {
      test(Context(url, broker))
    } finally {
      if (broker.isStarted) {
        broker.stop()
      }
    }
  }

  case class Context(url: String, broker: BrokerService)

} 
开发者ID:akka,项目名称:alpakka,代码行数:51,代码来源:JmsSpec.scala

示例2: ActiveMqBroker

//设置package包名称以及导入依赖的类
package scalasthlm.alpakka.playground

import javax.jms.ConnectionFactory

import akka.Done
import org.apache.activemq.ActiveMQConnectionFactory
import org.apache.activemq.broker.BrokerService

import scala.concurrent.{ExecutionContext, Future}



class ActiveMqBroker {

  var brokerService: Option[BrokerService] = None

  def start(): BrokerService = {
    val broker = new BrokerService()
    broker.setBrokerName("localhost")
    broker.setUseJmx(false)
    broker.start()
    brokerService = Some(broker)
    broker
  }

  def stop()(implicit ec: ExecutionContext): Future[Done] = {
    brokerService.fold(Future.successful(Done)){ broker =>
      Future {
        broker.stop()
        scala.concurrent.blocking {
          broker.waitUntilStopped()
        }
        Done
      }
    }
  }

  def createConnectionFactory: ConnectionFactory = new ActiveMQConnectionFactory(
    "vm://localhost?create=false")

}

object ActiveMqBroker extends ActiveMqBroker 
开发者ID:ScalaSthlm,项目名称:alpakka-integration-patterns,代码行数:44,代码来源:ActiveMqBroker.scala


注:本文中的org.apache.activemq.broker.BrokerService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。