关于 HTTP 服务的 Erlang 设计建议

发布于 2024-11-24 20:50:48 字数 666 浏览 0 评论 0原文

我是 Erlang 新手,但由于我的并发需求,我想开始使用一个感觉适用于该技术的应用程序。

这张照片突出了我想做的事情。

http://imagebin.org/163917

消息从队列中提取并路由到先前已处理的工作进程由于用户在 Django 应用程序中的表单中进行一些输入而进行设置。该设置需要一些额外的数据库(预先存在的数据库,因此我不想在这方面使用 ETS/DETS)查找,然后与消息路由器对话并创建相关进程。

我的问题是考虑到我将来可能想询问我的 Django 应用程序对于所有需要设置并首先给他们分配任务的工作人员,这里最好的沟通方式是什么。我喜欢 HTTP/ json,并且阅读了我在 Mochiweb 和 MochiJson 上能找到的一些内容,我认为这可以满足我的需求。我计划拥有一个 OTP 管理程序和应用程序,那么拥有一个单独的 mochiweb 进程然后将 erlang 消息传递到路由器是否明智?

我在 mochiweb 上遇到了一些困难,因为所有教程都在讨论如何使用脚本创建目录结构,这似乎将 mochiweb 以设计为中心 - 这不是我想要的,我想要一个轻量级的 mochiweb 进程偶尔会做一些工作。

请把这个拆开,欢迎大家评论。

干杯

戴夫

I'm new to Erlang but I would like to get started with an application which feels applicable to the technology due to the concurrency desires I have.

This picture highlights what i want to do.

http://imagebin.org/163917

Where messages are pulled from a queue and routed to worker processes which have previously been setup as a result of a user making some input a form in a Django app. The setup requires some additional database (preexisting database so I don't want to use ETS/DETS for this bit) lookup which then talks to the message router and creates a relevant process.

My issue comes with given that I may want to ask my Django app in the future for all the workers that need to be setup and task them in the first place, what is the best way to communicate here. I favour HTTP/ json and have read up what little I can find on Mochiweb and MochiJson and I think that would do what I want. I was planning on having a OTP supervisor and application, so would it be sensible to have a seperate mochiweb process which then passes erlang messages to the router?

I have struggled a little with mochiweb due to all the tutorials talking about how you use a script to create a directory structure, which seems to put mochiweb centric to a design - which isn't want I want here, I want a lightweight mochiweb process that does occassional work.

Please tear this apart, all comments welcome.

Cheers

Dave

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

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

发布评论

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

评论(1

残月升风 2024-12-01 20:50:48

mochiweb 很棒,但我认为您真正想要的是 webmachine。完整的文档可以在此处此处。简而言之,webmachine 是一个用于制作 REST 应用程序的工具包,我认为这就是您想要的。它在幕后使用 mochiweb,但隐藏了所有复杂(且未记录)的细节。当您创建 webmachine 项目时,您将获得完整的 OTP 应用程序和默认资源。从那里您将执行如下操作:

  1. 添加您自己的资源(或修改+重命名默认资源)。
  2. 修改调度程序,以便您的资源和路径对您的应用程序有意义。
  3. 添加代码来创建和监视您的工作进程 - 可能是一个 gen_server 和一个主管。请参阅本文和相关文章了解想法。请注意,您需要在创建项目时提供给您的主要主管的领导下启动这两个项目。
  4. 修改您的资源以与您的 gen_server 进行通信。

我没有完全遵循您提出的其他所有问题 - 在评论中回答任何后续问题可能会更容易。

mochiweb is awesome but I think what you actually want is webmachine. The complete documentation is available here and here. In a nutshell, webmachine is a toolkit for making REST applications, which I think is what you want. It uses mochiweb behind the scenes but hides all of the complex (and undocumented) details. When you create a webmachine project you'll get a complete OTP application and a default resource. From there you'll do something like the following:

  1. Add your own resources (or modify + rename the default one).
  2. Modify the dispatcher so your resources and paths make sense for your app.
  3. Add code to create and monitor your worker processes - probably a gen_server and a supervisor. See this and related articles for ideas. Note you'll want to start both under the main supervisor provided to you when you created your project.
  4. Modify your resources to communicate with your gen_server.

I didn't quite follow everything else you are asking - it may be easier to answer any follow-up questions in comments.

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