Ainterface provides APIs to communicate with Erlang processes, like Jinterface. And APIs of Ainterface are designed to integrate Akka with Erlang seamlessly.
Since Ainterface is an experimental project, there is no guarantee that APIs will not be changed.
- Published(non hidden) mode support
- Short node names support
- Non distributed mode support
- Provides binary pattern matching for ByteString
You should add the following dependency.
libraryDependencies += "com.okumin" %% "ainterface" % "0.1"
In application.conf,
akka {
ainterface {
# The name of root actor of ainterface-system.
root-name = "ainterface-system"
init {
# -name
# Makes the Erlang runtime system into a distributed node and configure the name.
name = "node-name-your-application"
# -setcookie
# Sets the magic cookie of the node to Cookie.
# If `setcookie` is not specified, `$HOME/.erlang.cookie` is used.
#setcookie = ""
}
}
}
First, start an Erlang node and EPMD.
$ erl -name mofu
Erlang/OTP 17 [erts-6.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Eshell V6.2.1 (abort with ^G)
([email protected])1>
Set up Ainterface.
scala> val config = com.typesafe.config.ConfigFactory.parseString("""
| akka {
| loglevel = "ERROR"
| ainterface {
| root-name = "ainterface-system"
| init.name = "ainterface-sample" // the node name
| }
| }
| """)
config: com.typesafe.config.Config = Config(SimpleConfigObject({"akka":{"ainterface":{"init":{"name":"ainterface-sample"},"root-name":"ainterface-system"},"loglevel":"ERROR"}}))
scala> val system = akka.actor.ActorSystem("sample", config)
system: akka.actor.ActorSystem = akka://sample
scala> akka.ainterface.AinterfaceSystem.init(system) // initialize
Start an echo server with the registered name echo
.
scala> val echo = system.actorOf(akka.actor.Props[ainterface.EchoActor])
echo: akka.actor.ActorRef = Actor[akka://sample/user/$a#1942167954]
You can send messages from the Erlang node to Akka!
The echo server returns his pid and hello
message.
([email protected])1> {echo, '[email protected]'} ! {self(), hello}.
{<0.38.0>,hello}
([email protected])2> flush().
Shell got {<6209.1.0>,hello}
ok
The other examples are here.
Apache 2.0