Coder Social home page Coder Social logo

akka-http-scala-docker-seed's Introduction

akka-http-scala-docker-seed

Sample akka-http seed project, ready for packaging with docker.

Operations

Run in Postman

Prerequisites

Structure

  • src/main/resources: configuration files

  • src/main/scala/com/vtex/akkahttpseed/actors: actor classes

  • src/main/scala/com/vtex/akkahttpseed/models: case classes and objects used for many reasons such as for request validation, response formats and marshalling (converting classes and objects to/from serialized formats, such as json).

  • src/main/scala/com/vtex/akkahttpseed/routes: classes that define routes (i.e. what paths and methods trigger which operations) and call whatever resources (actor operations, web services, etc) they need to complete their tasks.

  • src/main/scala/com/vtex/akkahttpseed/utils: utils directory contains code that is generic enough so as to be used in other projects.

  • src/main/scala/com/vtex/akkahttpseed/AkkaHttpScalaDockerSeed.scala: this file can be thought of as a "main" method. Here the actor system is started, others actors are started too and all routes are merged.

  • src/test: test classes

Behaviour

This sample app uses akka-http to expose operations that write and read to/from an AWS SQS queue.

In addition, a worker is started off when you start the application.

The worker will periodically (every 10 seconds) write sample messages to the queue.

This means that, when you read from the queue, chances are you will see messages sent automatically by the worker (as well as the ones you've manually sent using the write operation)

Installation & Running

Creating Intellij Project

When opening Intellij for the first time, check the Scala Plugin option so it gets downloaded too

  • Open Intellij and create a new project
  • Under Project location inform the location where you cloned this repo
  • Select 1.8 under Project SDK
  • Select 2.11.8 under Scala version (if unavailable, any other 2.11 version is fine too)
  • Check "Sources" and "Sources for SBT and plugins" unless your connection is poor
  • intellij

Run configuration

Once the intellij project is created, you need to define how you will run it:

  • Open Run -> Edit Configurations...
  • Click the green cross on the top left corner
  • Select SBT Task and create a run task, as per the following image:
  • img

Application configuration

You'll need to change some configuration in src/main/resources/application.conf, namely:

  • your queue name in SQS
  • the api key for using the stock quote API (use what's been given to you or get a new one at https://www.quandl.com/users/login)
  • the message that you want the automatic worker to write to the aforementioned queue

Docker packaging

This application uses sbt-native-packager which provides a docker plugin to package sbt projects.

Just run sbt docker:publishLocal at your project root.

Run docker container

If you're not running linux, replace ~/.aws with the path to the AWS configuration directory

After packaging the app as per the previous step, run $ docker ps --latest to see its name.

You should see a name like sample-project/akka-http-docker-seed:17fb541d99b587241d22f86d4170f65e6c40f9e1 (your exact values will be different)

To run the container containing your app, run the following command, while replacing the image name (as above) with your own value:

$ docker run -dit -v ~/.aws:/usr/sbin/.aws -p 5000:5000 sample-project/akka-http-docker-seed:17fb541d99b587241d22f86d4170f65e6c40f9e1

Test your application by opening http://localhost:5000/healthcheck on a web browser.

See also

Useful links

Akka and Scala running samples from Lightbend Activator The Reactive Manifesto

Feedback

Send feedback to [email protected] or [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.