GAMEON

Hands-on experiment building microservices and cloud native applications
View project on GitHub
There are lots of new technologies and application patterns associated with microservices. If you're like us, learning from reading someone's sample just isn't enough. Game On! is a throwback text adventure game whose purpose is to give intrepid developers who like to experiment "something to build". This blog describes our own misadventures as we do the same.

Devops Days in Raleigh

Venu Beyagudem, Jarek Gawor, Ranjan Kumar, and I (Heather Saunders) brought Game On! for its debut at DevOps Days in Raleigh, NC in early September.

DevOps days is a series of conferences across the world that covers topics of software development, IT infrastructure, and of course the DevOps principals that connect them and make them tick. Topics for speeches range from monitoring tool selection, to organizational culture. If you’re interested in seeing if DevOps days is coming near you, check out https://www.devopsdays.org.

IBM was a sponsor for the Raleigh conference, as well as a few others (find us in Ohio in November!), and wanted a little something more than just promotional material at the booth, so they asked if anyone might be able to present Game On! alongside the usual devops and developer tools.

As it turns out, Game On! was the perfect medium for engaging the attendees at the conference, who were mostly developers and devops professionals like us. They were interested in the game and the community around it. Once we explained that IBM was interested in helping developers learn in a fun and connected open source way, almost all the participants were interested in hearing more. A few even forgot that they had only approached the table to get their “conference passport” stamped in the first place.

I look forward to seeing how the game grows as a result of introducing it straight to developers at events like this, and am glad to have joined the Game On community myself!

Spring Room!

We have a new sample room written in Java with the Spring framework:

This post is a brief overview of the creation process.

Jumpstart with code gen

Using this guide, we made a Spring microservice starter that could be deployed to Bluemix with just a few commands:

  $ bx dev create
  ? Select a pattern:                        
  1. Web App
  2. Mobile App
  3. Backend for Frontend
  4. Microservice
  5. MFP
  Enter a number> 4

  ? Select a starter:
  1. Basic
  Enter a number> 1

  ? Select a language:
  1. Java - MicroProfile / Java EE
  2. Node
  3. Python
  4. Java - Spring Framework
  Enter a number> 4

  ? Enter a name for your project> springmsdemo                             
  ? Enter a hostname for your project> springmsdemo
  ? Do you want to add services to your project? [y/n]> y

  ? Select a service:
  1. Cloudant NoSQL Database
  2. Object Storage
  Enter a number> 1

  ? Select a service plan:               
  1. Lite
  2. Standard
  3. Dedicated Hardware
  Enter a number> 1

  Successfully added service to project.               

  ? Do you want to add another service? [y/n]> n
                                    
  The project, springmsdemo, has been successfully saved into the current directory.
  OK

Time to fill in our own code!

Borrowing from the Java room

The Java room had a lot of code we could reuse, so that’s what we did.

Notable differences:

1
2
3
4
5
6
7
8
9
10
11
12
  @Configuration
  @EnableWebSocket
  class WebSocketConfig implements WebSocketConfigurer {

      @Inject
      SocketHandler handler;

      public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
          registry.addHandler(handler, "/room");
      }
  }
  
  • We also needed to use a Spring WebSocket (org.springframework.web.socket.WebSocketSession) instead of the standard one (javax.websocket.Session). It looks roughly like this (simplified): (org.springframework.web.socket.WebSocketSession) instead of the standard one (javax.websocket.Session). It looks roughly like this (simplified):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  @Component
  public class SocketHandler extends TextWebSocketHandler {

      private final HashMap<String, WebSocketSession> sessions = new HashMap<>();
      @Inject
      private RoomImplementation roomImplementation;

      @Override
      public void afterConnectionEstablished(WebSocketSession session) throws Exception {
          sessions.put(session.getId(), session);
          session.sendMessage(new TextMessage(Message.ACK_MSG.toString()));
      }

      @Override
      public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
          sessions.remove(session.getId());
          Log.log(Level.INFO, this, "WebSocketSession with Id (" + session.getId() + ") closed with reason: " + status.getReason());
      }

      @Override
      public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
          roomImplementation.handleMessage(new Message(message.getPayload().toString()), this);
      }

      public void sendMessage(Message message) {
          for (WebSocketSession s : sessions.values()) {
              sendMessageToSession(s, message);
          }
      }

      private boolean sendMessageToSession(WebSocketSession session, Message message) {
          try {
              session.sendMessage(new TextMessage(message.toString()));
              return true;
          } catch (IOException e) {
              ...
          }
      }
      
      ...
  }
  

After porting some common code, we can run mvn spring-boot:run to see our Spring room running locally!

Deploying to Bluemix

After adding Travis, Docker, and JaCoCo, we were ready to deploy to Bluemix:

bx dev build

then

bx dev deploy

and our room is deployed as a Cloud Foundry service with a reachable endpoint!

Registering the room with Game On!

Done!

/teleport spring-sample

Simplified Docker Compose for local development

We now have a special branch in the gameon repository that contains a snapshot of a smooth end-to-end local development flow with docker-compose.

> git clone https://github.com/gameontext/gameon.git
> cd gameon
> ./go-admin.sh up

TA-DA!!

Yes, yes. Kubernetes is next, we promise. But with this revision of the Docker Compose path, we dropped a lot of complexity (bye, Amalgam8!) and created a simplified path for getting started. The README.md has been updated with the new TL;DR instructions, and they are ever so much better (and more concise!).

We’ll try to cut “releases” of the gameon repository a little more frequently, so there is always a last-known-good state to work from (rather than always using whatever the most recent / experimental docker images are).

More:

Stay tuned! Enjoy! Go play!

Headed to JavaOne 2017!

That’s right, Game On! is going back to JavaOne this year!

Frenetic activity has ensued (wow, does this feel familiar), as we prepare for the conference. If you’re a frequent visitor, there may be some bumps as we clean things up!

Both a Hands-on Lab and a general session feature the game. Be sure to put them on your schedule!

  • Introduction to Reactive Systems [HOL7896]

    In this two-hour workshop, IBM and Lightbend are teaming up to introduce you to developing reactive microservices on Kubernetes. Lagom is a microservice framework built atop Lightbend’s tried-and-proven distributed systems toolkit, Akka. This framework helps you build microservices as systems—reactive systems, to be precise—so that your microservices are elastic and resilient by nature. The reactive programming model aims to ensure systems availability and performance while processing streaming data. You will use Lagom’s development environment to avoid tedious setup and scripting when developing locally and will deploy your application to a Kubernetes cluster, so others in the workshop (and at JavaOne) can test out what you built.

    Track: Oracle Code: Containers, Microservices, DevOps, Databases, APIs, and more
    Experience Level: Advanced
    Session Type: HOL (Hands-on Lab) Session

    SPEAKERS

    • Erin Schnabel, Senior Software Engineer, IBM
    • Duncan DeVore, Principle Enterprise Architect, Lightbend
  • Choosing a NoSQL API and Database to Avoid Tombstones and Dragons in Game On! [CON1756]

    Game On! (@gameontext – http://gameontext.org) is an awesome throwback text-based adventure built with microservices. Completely open source, it enables everyone to choose their own adventure to learn about microservices concepts while extending the game. One of the core services is the Map, which maintains a two-dimensional map containing all the registered rooms. The Map started with a document store as a back end, but as the Map changed over time, tombstones started to accrue. And then people started to ask how to manage three dimensions, and dragons appeared. Come to this session to find out why the decision was made to change the NoSQL back end, how it was done, and the result of the change with a new NoSQL API (http://jnosql.org/).

    Track: Oracle Code: Containers, Microservices, DevOps, Databases, APIs, and more
    Experience Level: Intermediate
    Session Type: Conference Session

    SPEAKERS

    • Leonardo Lima, CTO, V2 Tecnologia Ltda.
    • Erin Schnabel, Senior Software Engineer, IBM
    • Otavio Santana, Developer, Soujava

We have a Scala Room!

What follows is the stream-of-conciousness and research that lead up to our newest sample room!

tl;dr

Day 0

So for me 2017/18 is going to include adventures in polyglot.

This will include but will not be only restricted to Kotlin,Prolog, Erlang, Racket, Haskell, Closure, Scala

Day 1

Decide on tooling.

Learn to stop hating and love regexes

scala> sample
res69: String =
roomHello,<roomId>,{
    "username": "username",
    "userId": "<userId>",
    "version": 1|2
}

scala> pattern
res70: scala.util.matching.Regex = (?s)(\w+),([^,]*),(.*)

scala> val pattern(target,id,payload) = sample
target: String = roomHello
id: String = <roomId>
payload: String =
{
    "username": "username",
    "userId": "<userId>",
    "version": 1|2
}

`

Room on a chip

Game On! is a fun little text adventure written using a Microservice architecture. It’s also extensible, allowing users to write their own ‘Rooms’ (locations within the text adventure world), that run as Microservices, in the cloud, on their own systems, etc.

I’ve played with Arduino’s and Raspberry Pi’s, and similar for quite some time. I tried having an Arduino read data from a Floppy Drive, which was fun, and ultimately led to a crazy floppy disk autoloader. From there, I ended up moving on from Arduino to the Maple, then from there to a Teensy 3.0, and most recently, a rather fun little collection of boards based around a Chip known as the ESP8266

esp8266 board

There are some nice things about one of the ESP8266 boards I had (Witty Cloud / GizWits):

  • you program it using the Arduino API,
  • it has built in WiFi, 4MB of flash to store your code, 64k of instruction ram, and 96k of data ram to play with.
  • it runs at 80mhz or so
  • it has an LED light that can change color
  • it has a light sensor

That’s pretty impressive for something that costs around 5$ shipped.

When you know there are Arduino JSON libraries, and Arduino WebSocket libraries that can run on it, you start wondering: is it possible to host a Room for Game On on an ESP8266 ?

I had a spare moment at a weekend, so decided to find out! =)

Swift and Watson Conversation Service

Thanks to @jkingoliver, we have a new advanced adventure combining Swift with Watson! This room uses the Watson Conversation Service to create a sandwich shop.

Go play!

Local development with Vagrant

Setting up the core game services locally can be a tricky business. If you don’t fancy installing our core game services and dependencies on your most favorite dev box, have a look at our Vagrant project clone the gameon repository, cd gameon, and run vagrant up, which will set up a virtual machine ready for local development.

Go play!

*Edit 2017-09-13: As noted above, using Vagrant for local development is now even easier. The gameontext/gameon-vagrant repository was retired in favor of a Vagrantfile in the gameontext/gameon repository itself.

Using JSR-107 Caching in Java-based rooms

Caching is one of those awkward bits of function you can totally avoid adding when first creating a bit of code. Everything will work just fine during your initial testing, but worries start to creep in when you start to consider what happens when running at scale: will remote services be invoked too frequently? And what happens to session data when processes are added or removed to accommodate changes in load?

There are many Caching libraries for Java, ranging from simple in memory thread safe caches, to distributed transactional remote based services. In this new two-part walkthrough, we’ll go through using Redis as a backing store for JSR-107 caching via the Redisson library.

We also have a new chronicle relating our experience using Redis in the game core:

Go play!

What's the weather like?

@rstephenrrtx has published a new chronicle relating his experience building a room that checks the weather using IBM Weather Company’s REST APIs: