A Simple Example of WebSocket based Microservice Architecure using Akka-HTTP in Scala


In my previous blog, I explained how you can implement WebSocket server using Akka-HTTP. As you know,  Microservice architecture has become very popular in recent years. This architecture fits perfect
1) When you want to give support of your application for many platforms such as web, mobile etc.
2) When your application consists of multiple services such as order service, account service, payment service etc.

In this blog, I have explained a simple example of WebSocket based Microservice Architecure using Akka-HTTP in Scala. You will see how WebSocket based Microservices can communicate with each other in a application.

2.jpg

In this example, there are two sub modules Account for Account related services and Order for Order related services. There is one more sub module Api, which will forward coming requests to their corresponding services.

Let’s create build.sbt for this multi module project.

Screenshot from 2016-08-08 00-48-08.png

Now create routes and its handler for Account service:-

Screenshot from 2016-08-08 00-55-29.png

Create routes and handler for Order service:-

Screenshot from 2016-08-08 00-55-45.png

Create routes and handler for Api service:-

Screenshot from 2016-08-08 00-55-52.png

You can find complete code here.

To run this example:-

– Open 3 terminals
– Execute `sbt “project api” run` from first terminal.
– Execute `sbt “project account” run` from second terminal.
– Execute `sbt “project order” run` from third terminal.
– Download `Dark Websocket terminal` web socket client extension of google chrome

1.png

You can find complete detail here to use this project.

KNOLDUS-advt-sticker

Advertisements

About Ayush Mishra

Ayush is the Sr. Software Consultant @ Knoldus Software LLP. In his 5 years of experience he has become developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality. .
This entry was posted in Akka, akka-http, Scala, Web Services, websocket and tagged , , , , . Bookmark the permalink.

One Response to A Simple Example of WebSocket based Microservice Architecure using Akka-HTTP in Scala

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s