iam.Carrot
iam.Carrot

Reputation: 5286

Add Web controllers to an Akka Actor System

I am working with Akka and Spring.

I have an actor System that operates on a Kafka Stream set up (using akka-stream-kafka_2.12) and the actors hold some data in memory and persist their state using akka-persistence.

What I wanted to know is that can I create a REST-endpoint that can interact with my Actor-System to provide some data or send messages to my actors.

My question is, how can it be achieved?

Upvotes: 1

Views: 402

Answers (1)

Unknown
Unknown

Reputation: 531

As said in the comments, I have created a sample working application in github to demonstrate the usage of Spring with Akka.

Please note that :

  1. I have used Springboot for quick setup and configuration.
  2. You can't expect any kind of good/best practices in this demo project as i had to create this in 30 mins. It just explains one of the ways(simple) to use akka within Spring.
  3. This sample cannot be used in microservice architure because there is no Remoting or Clustering involved here. API controllers directly talk to actors.
  4. In Controllers, Used GetMapping in all places instead of PostMapping for simplicity.
  5. Will update the repository with another sample explaining the usage with Clustering where the way of communication between API Controller and ActorSystem changes.

Here is the Link to Repo. Hope this will get you started.

Either you can build the application yourself or run the api-akka-integration-0.0.1-SNAPSHOT.jar file in command prompt. It runs in default 8080 port. This sample includes two kinds of APIs, /Calc/{Operation}/{operand1}/{operand2} and /Chat/{message}

/chat/hello

/calc/add/1/2

/calc/mul/1/2

/calc/div/1/2

/calc/sub/1/2

Edit:2

Updated the repo with Akka CLuster Usage in API

API-Akka-Cluster

Upvotes: 1

Related Questions