Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-erlang</artifactId>
<version>2.5.4</version>
</dependency>
Gradle:
groovy
implementation 'org.springframework.boot:spring-boot-starter-erlang:2.5.4'
application.properties:
spring.erlang.node.name=java_node
spring.erlang.node.cookie=erlang_cookie
spring.erlang.node.host=localhost
spring.erlang.node.port=5672
application.yml:
yaml
spring:
erlang:
node:
name: java_node
cookie: erlang_cookie
host: localhost
port: 5672
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.util.concurrent.SettableListenableFuture;
import com.ericsson.otp.erlang.*;
@Service
public class ErlangService {
@Autowired
private OtpNode otpNode;
public String callErlangFunction(String moduleName, String functionName, OtpErlangObject... functionArgs) {
OtpMbox mbox;
try {
mbox = otpNode.createMbox();
OtpErlangAtom module = new OtpErlangAtom(moduleName);
OtpErlangAtom function = new OtpErlangAtom(functionName);
OtpErlangList args = new OtpErlangList(functionArgs);
OtpErlangTuple tuple = new OtpErlangTuple(new OtpErlangObject[] { module, function, args });
mbox.send("erlang_node", tuple);
OtpErlangObject result = mbox.receive();
return result.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
private ErlangService erlangService;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
String result = erlangService.callErlangFunction("my_module", "my_function", new OtpErlangAtom("arg1"));
System.out.println("Result: " + result);
}
}