<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-erlang</artifactId> <version>1.0.0</version> </dependency> </dependencies> erlang -module(example). -export([start/0, hello_world/1]). start() -> register(example, spawn(?MODULE, loop, [])). hello_world(Message) -> example ! {hello_world, Message}. loop() -> receive {hello_world, Message} -> io:format("Received message: ~p~n", [Message]), loop() end. import org.springframework.beans.factory.annotation.Autowired; import org.springframework.erlang.core.ErlangTemplate; import org.springframework.stereotype.Component; @Component public class ErlangService { @Autowired private ErlangTemplate erlangTemplate; public void sendMessage(String message) { erlangTemplate.send("example", "hello_world", message); } } <bean id="erlangTemplate" class="org.springframework.erlang.core.ErlangTemplate"> <property name="connectionFactory" ref="erlangConnectionFactory"/> <property name="mailbox" value="erlangMessageQueue"/> </bean> <bean id="erlangConnectionFactory" class="org.springframework.erlang.connection.SingleConnectionFactory"> <property name="nodeName" value="node"/> <property name="host" value="localhost"/> <property name="cookie" value="erlang_cookie"/> <property name="port" value="5672"/> <property name="virtualHost" value="/"/> </bean> import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; @SpringBootApplication public class DistributedSystemApplication { public static void main(String[] args) { ConfigurableApplicationContext context = SpringApplication.run(DistributedSystemApplication.class, args); ErlangService erlangService = context.getBean(ErlangService.class); erlangService.sendMessage("Hello World"); } }


上一篇:
下一篇:
切换中文