Game On! is both a sample microservices app, and a throwback text adventure brought to you by the WASdev team at IBM. This app demonstrates how microservice architectures work from two points of view:
- As a Player: navigate through a network/maze of rooms, and interact with other players and the items or actions available in each room.
- As a Developer: extend the game by creating simple services that define rooms. Learn about microservice architectures and their supporting infrastructure as you build and scale your service.
You can learn more about Game On! at http://gameontext.org/.
This walkthrough will guide you through creating and deploying a simple room (a microservice) to the running Game On! app. This microservice is written in Java as a web app deployed on Spring.
The microservice can be (a) deployed as a Cloud Foundry app or (b) built into a docker container.
Game On! communicates with this service (a room) over WebSockets using the Game On! WebSocket protocol. Consider this a stand-in for asynchronous messaging like MQTT, which requires a lot more setup than a simple WebSocket does.
- Maven
- Java 8: Any compliant JVM should work.
- Create your own fork of this repository (what's a fork?)
- Create a local clone of your fork (Cloning a repository)
cd sample-room-spring
mvn spring-boot:run
After running this, the server will be running locally at http://localhost:8080/.
- Visiting this page provides a small form you can use to test the WebSocket endpoint in your service directly.
- A health URL is also defined by the service, at http://localhost:8080/health
You can also build a Docker image and run the app through there:
mvn install dockerfile:build
docker run -p 8080:8080 -t sampleroomspring
Then the server will be running locally at http://localhost:8080/.
For Game On! to include your room, you need to tell it where the publicly reachable WebSocket endpoint is. This usually requires two steps:
- hosting your service somewhere with a publicly reachable endpoint, and then
- registering your room with the game.
Creating a Docker image is straight-up: docker build .
right from the root menu.
A docker-compose.yml
file is also there, which can be used to specify overlay volumes to allow local development without restarting the container. See the Advanced Adventure for local development with Docker for a more detailed walkthrough.
We know, this walkthrough was simple. You have a nice shiny service that has a REST API (/health), and emulates async messaging behavior via a WebSocket. So?
The purpose of this text-based adventure is to help you grapple with microservices concepts and technologies while building something other than what you do for your day job (it can be easier to learn new things when not bogged down with old habits). This means that the simple service that should be humming along merrily with your name on it is the beginning of your adventures, rather than the end.
Here is a small roadmap to this basic service, so you can go about making it your own:
-
app.RoomImplementation
This class contains the core elements that make your microservice unique from others. Custom commands and items can be added here (via theapp.RoomDescription
member variable). The imaginatively namedhandleMessage
method, in particular, is called when new messages arrive. -
app.SocketHandler
The WebSocket endpoint for the service. -
app.HealthEndpoint
Defines the REST endpoint at/health
. -
src/test
-- Yes! There are tests!
Things you might try:
- Use RxJava to manage all of the connected WebSockets together as one event stream.
- Call out to another API (NodeRed integration, Watson API, Weather API) to perform actions in the room.
- Integrate this room with IFTTT, or Slack, or ...
- .. other Advanced Adventures!
Remember our https://gameontext.org/#/terms. Most importantly, there are kids around: make your parents proud.
This project is built using Maven and makes use of the Bluemix Developer CLI plugin to integrate with Spring and Bluemix. Visit this blog post to see how you can use the Bluemix CLI to quickly generate and deploy a Spring microservice.
The JaCoCo maven plugin is included in the build to generate code coverage reports. It will generate reports in multiple formats (HTML, XML, and CSV) in target/site/jacoco
.
You can also access code reports on the web at codecov.io if your project is a public Github project built with Travis. The included travis.yml
file includes a command to upload the code coverage reports automatically.