关于 HTTP 服务的 Erlang 设计建议
我是 Erlang 新手,但由于我的并发需求,我想开始使用一个感觉适用于该技术的应用程序。
这张照片突出了我想做的事情。
消息从队列中提取并路由到先前已处理的工作进程由于用户在 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mochiweb 很棒,但我认为您真正想要的是 webmachine。完整的文档可以在此处和此处。简而言之,webmachine 是一个用于制作 REST 应用程序的工具包,我认为这就是您想要的。它在幕后使用 mochiweb,但隐藏了所有复杂(且未记录)的细节。当您创建 webmachine 项目时,您将获得完整的 OTP 应用程序和默认资源。从那里您将执行如下操作:
gen_server
和一个主管。请参阅本文和相关文章了解想法。请注意,您需要在创建项目时提供给您的主要主管的领导下启动这两个项目。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:
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.gen_server
.I didn't quite follow everything else you are asking - it may be easier to answer any follow-up questions in comments.