本文整理汇总了Scala中com.lightbend.lagom.scaladsl.api.ServiceCall类的典型用法代码示例。如果您正苦于以下问题:Scala ServiceCall类的具体用法?Scala ServiceCall怎么用?Scala ServiceCall使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceCall类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: PlayerServiceImpl
//设置package包名称以及导入依赖的类
package com.chriswk.gameranker.player.impl
import java.util.UUID
import akka.actor.ActorSystem
import akka.persistence.cassandra.query.scaladsl.CassandraReadJournal
import akka.persistence.query.PersistenceQuery
import akka.stream.Materializer
import akka.stream.scaladsl.Sink
import com.chriswk.gameranker.player.api
import com.chriswk.gameranker.player.api.PlayerService
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.api.transport.NotFound
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry
import scala.concurrent.ExecutionContext
class PlayerServiceImpl(registry: PersistentEntityRegistry, system: ActorSystem)(implicit ec: ExecutionContext, mat: Materializer) extends PlayerService {
private val currentIdsQuery = PersistenceQuery(system).readJournalFor[CassandraReadJournal](CassandraReadJournal.Identifier)
override def createPlayer = ServiceCall { createPlayer =>
val playerId = UUID.randomUUID()
refFor(playerId).ask(CreatePlayer(createPlayer.name)).map { _ =>
api.Player(playerId, createPlayer.name)
}
}
override def getPlayer(playerId: UUID) = ServiceCall { _ =>
refFor(playerId).ask(GetPlayer).map {
case Some(player) => api.Player(playerId, player.name)
case None => throw NotFound(s"Player with id $playerId")
}
}
private def refFor(playerId: UUID) = registry.refFor[PlayerEntity](playerId.toString)
override def getPlayers = ServiceCall { _ =>
currentIdsQuery.currentPersistenceIds()
.filter(_.startsWith("PlayerEntity|"))
.mapAsync(4) { id =>
val entityId = id.split("\\|", 2).last
registry.refFor[PlayerEntity](entityId)
.ask(GetPlayer)
.map(_.map(player => api.Player(UUID.fromString(entityId), player.name)))
}
.collect {
case Some(p) => p
}
.runWith(Sink.seq)
}
}
示例2: Lagomneo4jsampleServiceImpl
//设置package包名称以及导入依赖的类
package com.inocybe.lagomneo4jsample.impl
import com.inocybe.lagomneo4jsample.api.Lagomneo4jsampleService
import com.inocybe.lagomneo4jsample.model.RecipeIn
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.{PersistentEntity, PersistentEntityRegistry}
import scala.concurrent.ExecutionContext
class Lagomneo4jsampleServiceImpl(persistentEntities: PersistentEntityRegistry) extends Lagomneo4jsampleService {
override def getRecipe(id: String) = ServiceCall { _ =>
// Look up the lagom-neo4j-sample entity for the given ID.
val ref = persistentEntities.refFor[Lagomneo4jsampleEntity](Lagomneo4jsampleService.entityId)
// Ask the entity the Hello command.
ref.ask(GetRecipe(id))
}
override def addRecipe = ServiceCall { _ =>
// Look up the lagom-neo4j-sample entity for the given ID.
val ref = persistentEntities.refFor[Lagomneo4jsampleEntity](Lagomneo4jsampleService.entityId)
// Tell the entity to use the greeting message specified.
ref.ask(AddRecipe())
}
}
示例3: Lagomneo4jsampleService
//设置package包名称以及导入依赖的类
package com.inocybe.lagomneo4jsample.api
import akka.{Done, NotUsed}
import com.inocybe.lagomneo4jsample.model.RecipeOut
import com.lightbend.lagom.scaladsl.api.transport.Method
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
object Lagomneo4jsampleService {
val entityId: String = "my-entity"
}
trait Lagomneo4jsampleService extends Service {
def getRecipe(id: String): ServiceCall[NotUsed, RecipeOut]
override final def descriptor = {
import Service._
// @formatter:off
named("recipe-service").withCalls(
restCall(Method.POST, "/recipes/", this.addRecipe),
restCall(Method.GET, "/recipes/:id", getRecipe _)
).withAutoAcl(true)
// @formatter:on
}
}
示例4: useGreeting
//设置package包名称以及导入依赖的类
package sample.helloworld.api
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.api.broker.Topic
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
import sample.helloworld.api.model.GreetingMessage
def useGreeting(id: String): ServiceCall[GreetingMessage, Done]
override final def descriptor = {
import Service._
// @formatter:off
named("hello").withCalls(
pathCall("/api/hello/:id", hello _),
pathCall("/api/hello/:id", useGreeting _)
).withTopics(
topic(HelloService.TOPIC_NAME, greetingsTopic)
).withAutoAcl(true)
// @formatter:on
}
// The topic handle
def greetingsTopic(): Topic[GreetingMessage]
}
object HelloService {
val TOPIC_NAME = "wordCount"
}
示例5: HelloServiceImpl
//设置package包名称以及导入依赖的类
package sample.helloworld.impl
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.api.broker.Topic
import com.lightbend.lagom.scaladsl.broker.TopicProducer
import com.lightbend.lagom.scaladsl.persistence.{EventStreamElement, PersistentEntityRegistry}
import sample.helloworld.api.model.GreetingMessage
import sample.helloworld.api.HelloService
class HelloServiceImpl(persistentEntityRegistry: PersistentEntityRegistry) extends HelloService {
override def hello(id: String) = ServiceCall { _ =>
// Look up the Hello entity for the given ID.
val ref = persistentEntityRegistry.refFor[HelloEntity](id)
// Ask the entity the Hello command.
ref.ask(Hello(id, None))
}
override def useGreeting(id: String) = ServiceCall { request =>
// Look up the Hello entity for the given ID.
val ref = persistentEntityRegistry.refFor[HelloEntity](id)
// Tell the entity to use the greeting message specified.
ref.ask(UseGreetingMessage(request.message))
}
override def greetingsTopic(): Topic[GreetingMessage] = {
TopicProducer.singleStreamWithOffset {
offset =>
persistentEntityRegistry.eventStream(HelloEventTag.instance, offset)
.map(ev => (convertEvent(ev), offset))
}
}
private def convertEvent(helloEvent: EventStreamElement[HelloEvent]): GreetingMessage = {
helloEvent.event match {
case GreetingMessageChanged(msg) => GreetingMessage(msg)
}
}
}
示例6: HelloConsumerServiceImpl
//设置package包名称以及导入依赖的类
package sample.helloworldconsumer.impl
import akka.stream.scaladsl.Flow
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry
import sample.helloworld.api.HelloService
import sample.helloworld.api.model.GreetingMessage
import sample.helloworldconsumer.api.HelloConsumerService
import sample.helloworldconsumer.impl.repositories.MessageRepository
class HelloConsumerServiceImpl (registery: PersistentEntityRegistry ,helloService: HelloService ,msgRepository:MessageRepository) extends HelloConsumerService {
helloService.greetingsTopic
.subscribe
.atLeastOnce(
Flow[GreetingMessage].map{ msg =>
putGreetingMessage(msg)
Done
}
)
var lastObservedMessage: String = _
private def putGreetingMessage(greetingMessage: GreetingMessage) = {
println(s"obersrve new message ${greetingMessage.message}")
entityRef(greetingMessage.message.toString).ask(SaveNewMessage(greetingMessage.message))
lastObservedMessage = greetingMessage.message
}
override def findTopHundredWordCounts(): ServiceCall[NotUsed, Map[String, Int]] = ServiceCall {
//fetch top 100 message and perform word count
req => msgRepository.fetchAndCountWordsFromMessages(100)
}
override def foo():ServiceCall[NotUsed, String] = ServiceCall{
req => scala.concurrent.Future.successful(lastObservedMessage)
}
private def entityRef(id: String) = registery.refFor[MessageEntity](id)
}
示例7: descriptor
//设置package包名称以及导入依赖的类
package sample.helloworldconsumer.api
import akka.NotUsed
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
import com.lightbend.lagom.scaladsl.api.transport.Method
import play.api.libs.json.{Format, Json}
trait HelloConsumerService extends Service {
override def descriptor = {
import Service._
named("wordCounts").withCalls(
restCall(Method.GET, "/api/wordcount", findTopHundredWordCounts _),
restCall(Method.GET, "/api/foo", foo)
).withAutoAcl(true)
}
def findTopHundredWordCounts(): ServiceCall[NotUsed, Map[String, Int]]
def foo(): ServiceCall[NotUsed, String]
case class WordDetails(word: String, count: String)
object WordDetails {
implicit val format: Format[WordDetails] = Json.format
}
}
示例8: LagomhandsondevelopmentServiceImpl
//设置package包名称以及导入依赖的类
package com.example.lagomhandsondevelopment.impl
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry
import com.example.lagomhandsondevelopment.api.LagomhandsondevelopmentService
class LagomhandsondevelopmentServiceImpl(persistentEntityRegistry: PersistentEntityRegistry) extends LagomhandsondevelopmentService {
override def hello(id: String) = ServiceCall { _ =>
// Look up the lagom-hands-on-development entity for the given ID.
val ref = persistentEntityRegistry.refFor[LagomhandsondevelopmentEntity](id)
// Ask the entity the Hello command.
ref.ask(Hello(id, None))
}
override def useGreeting(id: String) = ServiceCall { request =>
// Look up the lagom-hands-on-development entity for the given ID.
val ref = persistentEntityRegistry.refFor[LagomhandsondevelopmentEntity](id)
// Tell the entity to use the greeting message specified.
ref.ask(UseGreetingMessage(request.message))
}
}
开发者ID:negokaz,项目名称:lagom-hands-on-development.scala,代码行数:26,代码来源:LagomhandsondevelopmentServiceImpl.scala
示例9: createAccount
//设置package包名称以及导入依赖的类
package org.ioreskovic.greatmaterialcontinuum.api
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.api.transport.Method
import com.lightbend.lagom.scaladsl.api.{Descriptor, Service, ServiceCall}
trait AccountService extends Service {
def createAccount(): ServiceCall[Account, Done]
def deleteAccount(username: String): ServiceCall[NotUsed, Done]
def activateAccount(username: String): ServiceCall[NotUsed, Done]
def deactivateAccount(username: String): ServiceCall[NotUsed, Done]
def getAccount(username: String): ServiceCall[NotUsed, Account]
override final def descriptor: Descriptor = {
import Service._
// @formatter:off
named("accounts")
.withCalls(
restCall(Method.POST, "/api/accounts/", createAccount _),
restCall(Method.DELETE, "/api/accounts/:username", deleteAccount _),
restCall(Method.GET, "/api/accounts/:username/activation", activateAccount _),
restCall(Method.GET, "/api/accounts/:username/deactivation", deactivateAccount _),
restCall(Method.GET, "/api/accounts/:username", getAccount _)
)
.withAutoAcl(true)
// @formatter:on
}
}
示例10: AccountServiceImpl
//设置package包名称以及导入依赖的类
package org.ioreskovic.greatmaterialcontinuum.impl
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry
import org.ioreskovic.greatmaterialcontinuum.api.{Account, AccountService}
import org.ioreskovic.greatmaterialcontinuum.impl.cmd.acc._
import org.ioreskovic.greatmaterialcontinuum.impl.ent.acc.AccountEntity
class AccountServiceImpl(persistentEntityRegistry: PersistentEntityRegistry) extends AccountService {
override def createAccount(): ServiceCall[Account, Done] = ServiceCall { account =>
persistentEntityRegistry.refFor[AccountEntity](account.username).ask(CreateAccount(account))
}
override def deleteAccount(username: String): ServiceCall[NotUsed, Done] = ServiceCall { _ =>
persistentEntityRegistry.refFor[AccountEntity](username).ask(DeleteAccount(username))
}
override def activateAccount(username: String): ServiceCall[NotUsed, Done] = ServiceCall { _ =>
persistentEntityRegistry.refFor[AccountEntity](username).ask(ActivateAccount(username))
}
override def deactivateAccount(username: String): ServiceCall[NotUsed, Done] = ServiceCall { _ =>
persistentEntityRegistry.refFor[AccountEntity](username).ask(DeactivateAccount(username))
}
override def getAccount(username: String): ServiceCall[NotUsed, Account] = ServiceCall { _ =>
persistentEntityRegistry.refFor[AccountEntity](username).ask(RetrieveAccount(username))
}
}
示例11: HelloServiceImpl
//设置package包名称以及导入依赖的类
package se.hultner.hello.impl
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry
import se.hultner.hello.api.HelloService
class HelloServiceImpl(persistentEntityRegistry: PersistentEntityRegistry) extends HelloService {
override def hello(id: String) = ServiceCall { _ =>
// Look up the Hello entity for the given ID.
val ref = persistentEntityRegistry.refFor[HelloEntity](id)
// Ask the entity the Hello command.
ref.ask(Hello(id, None))
}
override def useGreeting(id: String) = ServiceCall { request =>
// Look up the Hello entity for the given ID.
val ref = persistentEntityRegistry.refFor[HelloEntity](id)
// Tell the entity to use the greeting message specified.
ref.ask(UseGreetingMessage(request.message))
}
}
示例12: createPlayer
//设置package包名称以及导入依赖的类
package com.chriswk.gameranker.player.api
import java.util.UUID
import akka.NotUsed
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
import play.api.libs.json.{Format, Json}
trait PlayerService extends Service {
def createPlayer: ServiceCall[CreatePlayer, Player]
def getPlayer(playerId: UUID): ServiceCall[NotUsed, Player]
def getPlayers: ServiceCall[NotUsed, Seq[Player]]
override def descriptor = {
import Service._
named("player").withCalls(
pathCall("/api/player", createPlayer),
pathCall("/api/player/:id", getPlayer _),
pathCall("/api/player", getPlayers)
)
}
}
case class Player(id: UUID, name: String)
object Player {
implicit val format: Format[Player] = Json.format
}
case class CreatePlayer(name: String)
object CreatePlayer {
implicit val format: Format[CreatePlayer] = Json.format
}
示例13: CollectSSHService
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.collect.ssh.api
import akka.Done
import com.lightbend.lagom.scaladsl.api.transport.Method
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
import org.wex.cmsfs.common.`object`.CoreMonitorDetailForSsh
object CollectSSHService {
val SERVICE_NAME = "collect-ssh"
}
trait CollectSSHService extends Service {
def pushCollectItem: ServiceCall[CoreMonitorDetailForSsh, Done]
override final def descriptor = {
import Service._
import CollectSSHService._
named(SERVICE_NAME).withCalls(
restCall(Method.POST, "/v1/collect", pushCollectItem)
)
}
}
示例14: NotificationService
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.notification.impl
import com.lightbend.lagom.scaladsl.api.{CircuitBreaker, Service, ServiceCall}
object NotificationService {
val SERVICE_NAME = "notification"
}
trait NotificationService extends Service {
def pushNotificationItem: ServiceCall[String, String]
override final def descriptor = {
import NotificationService._
import Service._
named(SERVICE_NAME).withCalls(
pathCall("/mns-web/services/rest/msgNotify", pushNotificationItem)
.withCircuitBreaker(CircuitBreaker.identifiedBy("alarm-circuitbreaker"))
)
}
}
示例15: ElasticsearchService
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.elasticsearch.api
import akka.Done
import com.lightbend.lagom.scaladsl.api.{CircuitBreaker, Service, ServiceCall}
import com.lightbend.lagom.scaladsl.api.transport.Method
object ElasticsearchService {
val SERVICE_NAME = "elastic-search"
}
trait ElasticsearchService extends Service {
def pushElasticsearchItem(_index: String, _type: String): ServiceCall[String, Done]
override final def descriptor = {
import ElasticsearchService._
import Service._
named(SERVICE_NAME).withCalls(
restCall(Method.POST, "/:_index/:_type", pushElasticsearchItem _)
.withCircuitBreaker(CircuitBreaker.identifiedBy("elasticsearch-circuitbreaker"))
)
}
}