Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interface against other networked applications using Erlang?

I'm learning erlang and I'm very fascinated by the mnesia db. I want to build some real world application in C# / F# using erlang as backend.

I'm searching for a good solution to communicate with erlang nodes from the outside world.

What I found so far:

(A) OTP.net, an opensource .net library implementing the 'native' erlang comunication protocol

Problems here:

  • The library is not very mature
  • I don't like the object model ported from Java (too many almost exact replicas of BCL classes)
  • I don't like the threading model use for connections.
  • Many open TCP ports are required
  • Lack of security

(B) Use ports / sockets in erlang and implement a custom protocol.

Problems here:

  • I don't have any experience
  • Hard to maintain / expand for future versions

Do you have any advice, experience in this topic?

Should I work on the OTP.net library to make it fit my needs or try to implement a new protocol from scratch?

What about a JSON or REST solution? Is there any erlang library that would do the trick?

like image 884
Luca Martinetti Avatar asked Apr 30 '09 14:04

Luca Martinetti


3 Answers

The port/socket solution is a good idea and is not hard as it may seem. Google's protocol buffers is just what you need. It is very easy to use, efficient and maintainable. It has implementations for C#, erlang, java, python and many more (See OtherLanguages and developer guide)

You can use protocol buffers to define the request and response protocol structure. Then use it to communicate between erlang and any other supported language. The tutorial will explain it all. After that all you need to do is send the response over the port.

The advantage of this approach is that:

  1. You can easily extend and change the protocol in the future
  2. It is much more efficient than the REST approach
  3. It is currently used by Google for almost all of its internal RPC protocols and file formats
like image 124
Nadia Alramli Avatar answered Nov 02 '22 00:11

Nadia Alramli


If you want to implement a REST API in Erlang there is only one thing to do. Use the excellent MochiWeb Kit to build your own HTTP server that implements your protocol.

Don't panic, it really is easier than it would appear.

There are a number of tutorials about how to do it including a screencast set from the Pragmatic Programmers.

It comes with a complete set of json libraries, so you'll be fine!

like image 38
Gordon Guthrie Avatar answered Nov 02 '22 00:11

Gordon Guthrie


Sure, you can do REST with Erlang, see e.g. http://www.infoq.com/articles/vinoski-erlang-rest - if appropriate for your apps' needs, REST is an excellent approach. (Pycon Italia Tre, next week in Florence, has sessions on Erlang/Python cooperation, see www.pycon.it if you're near Tuscany;-).

like image 2
Alex Martelli Avatar answered Nov 01 '22 22:11

Alex Martelli