https://github.com/linux-china/akka-spring-boot-starter
akka-spring-boot-starter
https://github.com/linux-china/akka-spring-boot-starter
Last synced: about 1 year ago
JSON representation
akka-spring-boot-starter
- Host: GitHub
- URL: https://github.com/linux-china/akka-spring-boot-starter
- Owner: linux-china
- Created: 2019-01-07T23:55:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-08-23T23:49:20.000Z (almost 5 years ago)
- Last Synced: 2025-04-02T02:51:07.183Z (over 1 year ago)
- Language: Java
- Size: 26.4 KB
- Stars: 6
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Spring Boot Starter Akka
========================
Spring Boot 2.0 starter for Akka.
### How to use
* please add following dependency in your pom.xml
```xml
org.mvnsearch.spring.boot
akka-spring-boot-starter
1.0.0-SNAPSHOT
```
* Write Akka Actor like spring with @ActorComponent
```
@ActorComponent
public class GreetingActor extends AbstractActor {
@Autowired
private GreetingService greetingService;
@Override
public Receive createReceive() {
return receiveBuilder()
.match(String.class, text -> {
System.out.println(greetingService.greet(text));
})
.build();
}
}
```
* Add actor ref in init method
```
@RestController
public class PortalController extends AkkaSpringSupport {
private ActorRef greetingActor;
@PostConstruct
public void init() {
greetingActor = actorOf(GreetingActor.class);
}
@RequestMapping("/hello/{name}")
public String hello(@PathVariable(name = "name") String name) {
greetingActor.tell(name, ActorRef.noSender());
return "sent";
}
}
```
### Akka configuration
Configuration in application.properties will replace settings in Akka configuration file.
* Akka Actor
```properties
akka.actor-provider=local
```
* Akka Remote
```properties
akka.actor-provider=remote
akka.listen-port=2552
```
* Akka Cluster
```
akka.actor-provider=cluster
akka.listen-port=0
akka.cluster-seed-nodes=akka.tcp://ClusterSystem@127.0.0.1:2551,akka.tcp://ClusterSystem@127.0.0.1:2552
akka.extensions=akka.cluster.client.ClusterClientReceptionist
```
* Akka configuration file
```
akka.conf=classpath:/application.hocon
```
### FAQ
##### How to set Akka configuration?
Please add following setting in your application.properties
```
akka.conf=classpath:/application.conf
```
### References
* Akka Quickstart with Java: https://developer.lightbend.com/guides/akka-quickstart-java/index.html
* Akka Chinese document: https://doc.yonyoucloud.com/doc/akka-doc-cn/2.3.6/scala/book/chapter1/01_what_is_akka.html
* Introduction to Spring with Akka: https://www.baeldung.com/akka-with-spring
* Reactive Programming with Akka: https://dzone.com/refcardz/reactive-programming-akka?chapter=1