Code Monkey home page Code Monkey logo

nvwa's Introduction

Nüwa

This is a archetype project (or seed project) for building up micro-service. Nüwa, also known as Nügua, is a goddess in ancient Chinese mythology best known for creating mankind and repairing the pillar of heaven. (from Wikipedia)

Features

  • BDD with cucumber-jvm
  • Stream module
  • Travis-CI & Coveralls support

Requirements

  • Java 1.8.0_05 or above
  • Scala 2.11.6 or above
  • Activator 1.3.4 or above
  • sbt 0.13.8 or above

Template Usage

1. Pre-installation

1.1 Install JavaSE (Java 1.8.0_05 or above)**

1.2 Install Scala (Scala 2.11.6 or above)**

1.3 Install Activator (Activator 1.3.4 or above)**

Both mini-package and full-package are OK.

1.4 Git pull repo

  • Step 1. pull repo
git clone https://github.com/truman-misfit/nvwa.git
  • Step 2. activator run
cd nvwa
activator run

Or you can test cucumber by following the commands below:

activator cucumber

2. Configuration

2.1 Stream

Stream is a AWS Kinesis Publisher/Consumer module.

Using dependency injection, you can integrate Stream module into your self-customized services.

  • Step 1. add StreamPlugin in play.plugins append the line below the play.plugins file:
1000:com.misfit.microservices.plugins.StreamPlugin
  • Step 2. define yourself StreamJob classes For example: One job for Logging
import play.api.Logger
import com.misfit.microservices.modules._

object PrintLogSampleJob extends StreamJob {
	override def registerService = "ms.backend.stream.log"
	override def onEvent(event: String) = {
		val output = "Received event from log stream: " + event
		Logger.info(output)
	}
}

Another job for mailing

import play.api.Logger
import com.misfit.microservices.modules._

object PrintMailSampleJob extends StreamJob {
	override def registerService = "ms.backend.stream.mail"
	override def onEvent(event: String) = {
		val output = "Received event from mail stream: " + event
		Logger.info(output)
	}
}

You can define your own consumer jobs with extending StreamJob trait and overriding the methods below:

// Your stream name. Each consumer should be assigned a stream
override def registerService = ""
// your real job procedure is defined in this callback function
override def onEvent(event: String) = {}
  • Step 3. register your jobs in the application.conf file Add the lines below into applicaion.conf:
# Stream Module
# ~~~~~
# Stream module enabled
play.modules.enabled += "com.misfit.ms.modules.stream.StreamPublisher"
play.modules.enabled += "com.misfit.ms.modules.stream.StreamConsumer"

# You can manually disable publisher or consumer
# module.ms.module.stream.publisher.enabled = false
# module.ms.module.stream.consumer.enabled = false

# Stream mode and connection info
module.ms.module.stream.mode = "kinesis"
module.ms.module.stream.region = "us-east-1"
module.ms.module.stream.app = "ms.backend.stream.demo"

# Stream jobs
module.ms.module.stream.jobs += "com.misfit.ms.modules.stream.jobs.PrintLogSampleJob"
module.ms.module.stream.jobs += "com.misfit.ms.modules.stream.jobs.PrintMailSampleJob"
  • Step 4. publish to a specific stream
class Application @Inject()(publisher: StreamPublisherAbstract) extends Controller {

	def pushToMailStream = Action {
		publisher.publish("ms.backend.stream.mail", "this is for mail stream.")
		Ok
	}

	def pushToLogStream = Action {
		publisher.publish("ms.backend.stream.log", "this is for log stream.")
		Ok
	}
}

2.2 BDD

BDD is implemented via cucumber-java. For details you can see the cucumber-jvm Github Page: cucumber/cucumber-jvm

You can self-define the cucumber default directory by modify the configs in build.sbt. Here is sample:

// Play2-cucumber integration
cucumberSettings

cucumberFeaturesLocation := "./test/BDD/features"

cucumberStepsBasePackage := "features.steps"

Future

  • Local mode for Stream module(a internal message queue)
  • Kafka integration in Stream module
  • Cache module(a centralized cache system powered by Redis/ElastiCache)

Author

[email protected]

nvwa's People

Contributors

truman-misfit 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.