GithubHelp home page GithubHelp logo

lagom-toggle-router's Introduction

XPTO

1. Install

1.1 Start by installing sbt

MAC OS X

brew install sbt

Linux

sudo apt-get install sbt

Windows

Download the installer

1.2 Checkout the project

git clone [email protected]:pdcarv/lagom-toggle-router.git

1.3 Run the project

Change into the project directory and, in your terminal of choice, type:

sbt runAll

This will run all services along with an embedded kafka and cassandra server.

2. Usage

Get a toggle

curl http://localhost:9000/api/v1/toggle/:id/version/:version

Where id and version are the Toggle's corresponding id and version.

Lagom defines a PersistentEntity API that uses event sourcing. This means that we are persisting events, and deriving their current state from their history. As there is no mutation of data, it means a high transaction rate and less concurrency and consistency issues. This example uses PersistentEntities. Lagom implements persistent entities on top of cassandra keystore.

Create or Update

Sample is as follow. Please note that user token is mocked in the current version. There is no token generation strategy. This will also trigger a notification to other services.

curl -H "User-Token: Xm28dxc" -X POST -d '{"id": "3", "name": "isButtonGreen", "version": "2", "service": "abc", "permission": true, "enabled": true }' http://localhost:9000/api/v1/toggle

There are several strategies for asynchronous communication in lagom, akka's distributed pub/sub and the message broker api stick out. The message broker api reads and writes to and from an event stream, in lagom terminology this is known as subscribing or publishing to a Topic. That capability is provided by a kafka instance that comes bundle in development environment, no configuration needed. Lagom uses kafka providing two strategies for subscribers, atLeastOnce and atMostOnceSource. We're using atLeastOnce in this example which guarantees that a configuration change notification is consumed, at least once or possiblyt more than once.

Check if Toggle is enabled

curl http://localhost:9000/api/v1/toggle/:id/version/:version/enabled

Message serialization is provided by default, though one can implement their own serialization for each endpoint. In a similar mechanism one can customize HTTP header requests or responses by writing custom principals. This keeps transport logic separate from our services. A sample authentication is provided using a custom security header.

Conductr comes bundle for service discovery that we're not using in this example. However for a production environment we might want to use something as consul for discovery and service authorization.

3. Tests

Ensure you're running sbt and then just type.

test

This will run all tests, if you just want to run one test, use:

testOnly com.xpto.impl.<TestClass>

lagom-toggle-router's People

Contributors

pdcarv avatar

Watchers

 avatar

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.