使用 akka 和 scala 实现请求/响应协议的最佳方法是什么?

发布于 2024-11-14 23:56:14 字数 471 浏览 7 评论 0原文

我一直在研究如何开发一个分布式架构,通过参与者使用并发概念来实现协议请求/响应。

我的结论是,做到这一点的最佳方法是创建一个同步处理 Futures/Promises 的响应系统,并在响应后不久,留下一个开放的通道来接收通知。

因此,架构的工作方式与收件箱消息完全相同。

它有一些问题。

因此我必须维护两个端点(两层中的参与者)?

问题: 视图模块请求处理特定元素。她发送此命令以通过应用程序服务器上的 RemoteActor 进行处理。该服务器应该立即返回一个承诺,即在处理元素时它将通知您。此后,视图模块将等待处理完成的通知。

您如何看待这个问题?

我正在使用 Scala、Akka 和 Google Guice。

我相信这是一个普遍问题,每个人都可以利用他们的解决方案。如果我损害了 stackoverflow 网站的条款,请原谅。

提前致谢

I've been studying about how I could develop a distributed architecture that implements the protocol request/response using the concept of concurrency through actors.

I concluded that the best way to do this is by creating a response system with synchronous handling of Futures/Promises, and soon after the response, leaving an open channel to receive notifications.

Thus an architecture that would work exactly like a inbox message.

It has some problems.

Thus I would have to maintain two endpoints (actors in the two layers)?

The Problem:
The view module requests that a particular element is processed. She sends this command to be processed via RemoteActor on the application server. This server should immediately return the promise that it will notify you when the element is processed. After this, the view module will be waiting the notification of completion of processing.

How do you see this problem?

I am using Scala, Akka and Google Guice.

I believe it is a generic problem that everyone can make use of their solutions. Excuse me if I'm hurting the terms of stackoverflow site.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嘿咻 2024-11-21 23:56:14

我不想分散您在 Akka 上可能得到的任何好的答案的注意力,因为不幸的是,我对 Akka 及其分布式 Actor 功能了解不多,但我想问您是否考虑过任何替代方案。

看来你基本上需要一个异步RPC库。据我所知,有两个用 Scala 编写的强大库可以满足您的要求 - http://sna-projects。 com/norbert/http://twitter.github.com/finagle/。 Finagle 提供了一些非常强大的组合器,用于表达异步计算依赖关系并在 future 上注册监听器。我目前正在维护 Norbert,我们在 LinkedIn 中将其用于一些分布式系统,例如搜索。

I don't want to distract from any good answers you may get on Akka, because I unfortunately don't know much about Akka and it's distributed actors features, but I'd like to ask if you've considered any alternatives.

It seems that you basically need an asynchronous RPC library. There are two powerful libraries written in Scala that I know of that may satisfy your requirements - http://sna-projects.com/norbert/ and http://twitter.github.com/finagle/. Finagle gives some really powerful combinators for expressing asynchronous computation dependencies and registering listeners on futures. I'm currently maintaining Norbert, which we use at LinkedIn for some of our distributed systems, such as search.

全部不再 2024-11-21 23:56:14
//On "server" node
class SomeActor extends Actor {
  def receive = {
    case messageToRemoteActor => self reply_? TypeOfResponseMessage()
  }
}

Actor.remote.register("myRemoteActor", actorOf[SomeActor])

//On "client" node
val remoteActor = Actor.remote.actorFor("myRemoteActor", "hostnameOrIpOfNodeContainingTheActorAbove", port)

val f: Future[TypeOfResponseMessage] = remoteActor !!! messageToRemoteActor

f.onComplete( _.value.get match {
  case Left(exception) => handle(exception)
  case Right(result) => handle(result)
})
//On "server" node
class SomeActor extends Actor {
  def receive = {
    case messageToRemoteActor => self reply_? TypeOfResponseMessage()
  }
}

Actor.remote.register("myRemoteActor", actorOf[SomeActor])

//On "client" node
val remoteActor = Actor.remote.actorFor("myRemoteActor", "hostnameOrIpOfNodeContainingTheActorAbove", port)

val f: Future[TypeOfResponseMessage] = remoteActor !!! messageToRemoteActor

f.onComplete( _.value.get match {
  case Left(exception) => handle(exception)
  case Right(result) => handle(result)
})
深海少女心 2024-11-21 23:56:14

为什么不只使用 0MQ 的 REQ-REP 套接字之一?

https://github.com/zcox/akka-zeromq-java

这样你就解决了解决您眼前的问题,同时开始学习一种架构,它将带您走很长的路,并支持与用多种语言编写的客户端进行通信。

有关这可能导致的示例,请查看 http://blog.getintheloop.eu/2009/05/22/lift-amqp-with-rabbitmq-and-scala-tutorial-and-screencast/

请注意,我建议您现在使用 AMQP,因为 RabbitMQ 代理对于您眼前的问题来说太过分了。相反,我建议您投入时间使用从长远来看会给您带来红利的架构(消息队列)。

Why not just use one of 0MQ's REQ-REP sockets?

https://github.com/zcox/akka-zeromq-java

That way you solve your immediate problem and at the same time, begin learn an architecture that will take you a long way and supports communications with clients written in many languages.

For an example of where this might lead look at http://blog.getintheloop.eu/2009/05/22/lift-amqp-with-rabbitmq-and-scala-tutorial-and-screencast/

Note that I am NOT suggesting that you use AMQP today since a RabbitMQ broker would be overkill for your immediate problem. Rather, I am suggesting that you invest your time in using an architecture (message queueing) that will pay you dividends in the long run.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文