Skip to content

Commit

Permalink
deploy: 8c5f688
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Nov 8, 2023
1 parent 5ed6423 commit 3f61918
Show file tree
Hide file tree
Showing 113 changed files with 261 additions and 578 deletions.
7 changes: 2 additions & 5 deletions 2016/05/11/cars-pi-cameras-ascii-art.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<!doctype html><html lang=en><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1"><link rel=stylesheet href=https://use.fontawesome.com/e3112f1bdf.css><link rel=stylesheet href=/css/flex.min.82916dff37dfd913211404396f31b8f7eecf60f393cfd65ec00c0d7df8dafcb6.css><link rel="shortcut icon" href=/favicon.ico type=image/x-icon><title>GO: Cars, Pi cameras and ASCII art&amp;#58; Microservices with Liberty and Game On!</title><link rel=canonical href=/2016/05/11/cars-pi-cameras-ascii-art.html><link rel=alternate type=application/rss+xml href=/blog/index.xml title="Game On! Adventures with microservices"></head><body><header class=head-single><h1><a href=/>GAME<span class=on>ON</span></a></h1><div>Hands-on experiment building microservices and cloud native applications</div></header><nav class=project><a target=_blank href=https://gameontext.org title="Play the game"><i class="fa fa-play" aria-hidden=true></i><span>Play <span>the game</span></span></a>
<a href=/about/ title="Read the book"><i class="fa fa-book" aria-hidden=true></i><span>Learn <span>more</span></span></a>
<!doctype html><html lang=en><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="chrome=1"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1"><link rel=stylesheet href=https://use.fontawesome.com/e3112f1bdf.css><link rel=stylesheet href=/css/flex.min.82916dff37dfd913211404396f31b8f7eecf60f393cfd65ec00c0d7df8dafcb6.css><link rel="shortcut icon" href=/favicon.ico type=image/x-icon><title>GO: Cars, Pi cameras and ASCII art&amp;#58; Microservices with Liberty and Game On!</title><link rel=canonical href=/2016/05/11/cars-pi-cameras-ascii-art.html><link rel=alternate type=application/rss+xml href=/blog/index.xml title="Game On! Adventures with microservices"></head><body><header class=head-single><h1><a href=/>GAME<span class=on>ON</span></a></h1><div>Hands-on experiment building microservices and cloud native applications</div></header><nav class=project><a href=/about/ title="Read the book"><i class="fa fa-book" aria-hidden=true></i><span>Learn <span>more</span></span></a>
<a href=/blog/ title="Read the blog"><i class="fa fa-newspaper-o" aria-hidden=true></i><span>Read <span>our blog</span></span></a>
<a target=_blank href=https://gameontext.org/slackin/ title="Join our slack team"><i class="fa fa-slack" aria-hidden=true></i><span><span>Join us on</span> Slack</span></a>
<a target=_blank class=github href=https://github.com/gameontext title="View project on GitHub"><i class="fa fa-github" aria-hidden=true></i><span>Github</span></a></nav><article class=post><header><h1>Cars, Pi cameras and ASCII art&amp;#58; Microservices with Liberty and Game On!</h1><div class=byline><div><time class=post_date>11 May 2016</time> by
&nbsp;<address class=author><a rel=author target=_blank href=https://github.com/>adam_P</a></address></div><div class=tags>tags:<ul><li>&nbsp;<a href=/tags/#iot>iot</a></li><li>&nbsp;<a href=/tags/#hacking>hacking</a></li></ul></div></div></header><section class=content><blockquote><p>Post recovered from the Liberty development blog. Pictures are missing (we'll find them eventually).</p></blockquote><p>The Liberty microservices team, based in IBM Hursley in the UK, decided to include some ASCII art in Game On!. From there, it was but a short step to driving a remote-controlled car around the floor of the latest WebSphere User Group meeting at IBM Southbank, taking pictures with a Raspberry Pi camera to render as ASCII art.</p><h2 id=game-on>Game On!</h2><p>Game On! is both a sample microservices application and throwback text adventure brought to you by the WASdev team at IBM. It aims to enable exploration of microservice architectures from two points of view:</p><ul><li><p><strong>As a player</strong>: On the one hand, you can be entertained by the creativity of other peer developers, exploring the game’s rooms; on the other hand, you can navigate a distributed system, exit by exit.</p></li><li><p><strong>As a developer</strong>: Learn about microservice architectures and supporting infrastructure by extending the game with your own services. Write your own rooms to see how they interact with the rest of the system and to experiment with different strategies for building resilient distributed systems.</p></li></ul><h2 id=polyglot-to-the-rescue>Polyglot to the rescue</h2><p>Text is one way to display information to the user but we wanted to add images. Game On! is text-based, though, and doesn’t support images. So we thought it would be cool if we could display some ASCII art and, even better, provide a way for images to be converted on-the-fly.</p><p>Our initial approach was to create a new room for Game On! which would display some ASCII art pictures (we imaginatively titled this the picture room). This would be hosted in its own Docker container and it would register with the Game On! map service at startup. The <a href=https://github.com/gameontext/gameon-simpleroom>simple Java room example</a> provided a good starting point. It shows all the skeleton code needed to connect a room to Game On! and how to handle things like security and creating the correct JSON data structures. Great, we were up and running with a new Game On! room in about 10 minutes (after a few minor tweaks to the Java code, such as setting the correct developer API key).</p><p>Now all we needed was a Java library to do the image-to-ASCII conversion for us and we would be good to go. Unfortunately, this wasn’t as easy as it first sounded because there isn’t a readily available library for Java. The library that a lot of people use is <a href=https://www.graphicsmagick.org/>GraphicsMagick</a> but that is native code. A little bit of searching revealed that there exists a node.js module called <a href=https://www.npmjs.com/package/image-to-ascii>image-to-ascii</a>. Normally this would be the end of the investigation, but with microservices we could quickly add in a new technology, even from other runtimes and languages.</p><p>We configured a Docker container to run a node.js instance with the image-to-ascii module installed. We then added a very simple web interface with <a href=https://www.npmjs.com/package/express>express</a>: not even REST, just an endpoint that accepts an image and returns ASCII art. We called this the image service. After that, we just configured the Game On! room to call out to the image service.</p><p>So now we have a nice polyglot environment and, because IBM Bluemix supports both node.js and Liberty runtimes, there won’t be a problem when we deploy this to the cloud in the future.</p><h2 id=smile-please>Smile please</h2><p>Once we had static images, we immediately wanted to use a camera to capture live pictures; something altogether much more interesting (oh look, new shiny!). We had a camera in the office that plugged into a Raspberry Pi; Liberty is such a lighweight application server that it happily runs on a Pi. So we built another Game On! room (again based on the Java simple room template) but moved it be running on the Pi: we called this the camera room (you can tell we’re in development and not marketing…). Here is a picture showing the room running in Game On! and the camera taking a picture of one of the team (note the obligatory coffee pot in the foreground, this was a bit of a late night coding session in the office :-) ):</p><p>[[Game On! camera and ascii art]]</p><p>This was interesting as it was starting to not only show how to communicate with devices (think Internet of Things) but also what happens when more than one person tries to control the same physical device. The increasing number of microservice interactions between Game On!, node, and the Pi also nicely serves to illustrate the fact that increased remote calls is something that is part of a microservices environment. The good news is that Game On! contains plenty of code showing how to do things like re-establishing WebSocket connections, handling timeouts, and a whole plethora of things that can happen when one service tries to call another.</p><h2 id=backseat-drivers>Backseat drivers!</h2><p>Having got the camera working, always getting the same image (albeit a live one instead of a static one) soon got a little bit boring. We needed a way to move the camera around so that it could take different pictures. Enter the Liberty Car. For those that don’t know, the Liberty Car is a remote-controlled car that is controlled using a Liberty instance running on a Pi, which is housed within the car. Hhhmmm, so that would be something that can be moved using a Pi…perfect! We removed the old Pi that was in the car and replaced it with the one running our Game On camera room:</p><p>[[Liberty Car and Camera]]</p><p>One of the key tenets of microservices is the separation of concern between services and how each one should have a clearly defined responsibility. Rather than add functionality to the camera room, we added another room to control the car (car room). To that end, we further decomposed the existing camera room into a camera service that would let you take a picture and could be accessed independently from Game On.</p><p>Earlier, I mentioned how increased numbers of remote calls, and their associated overheads, are one of the costs of using a microservices architecture. The sample flows below show just how quickly these calls start to add up, and why you need to be defining your API up front: think Test Driven Development but with APIs and Swagger.</p><p>Taking a picture:</p><pre><code>Browser &lt;-&gt; Game On (docker) &lt;-&gt; Car Room (Pi) &lt;-&gt; Camera Service (Pi) &lt;-&gt; Image Service (node.js)
</code></pre><p>Driving the car:</p><pre><code>Browser &lt;-&gt; Game On (docker) &lt;-&gt; Car Room (Pi) &lt;-&gt; Car Service (Pi)
</code></pre><p>Re-using the camera service:</p><pre><code>3rd Party App &lt;-&gt; Camera Service (Pi)
</code></pre><h2 id=the-final-picture>The final picture</h2><p>At a high level, this is how we had all the services talking to each other:</p><p>[[GameOn Demo Architecture]]</p><p>This architecture shows:</p><ul><li>A virtual machine with 7 Docker containers, each running an instance of Liberty</li><li>A polyglot environment with both node.js and Liberty runtimes</li><li>A Raspberry Pi running Liberty, with 4 deployed applications</li><li>Service re-use; being able to drive the car, or take pictures, through Game On! or using a second web interface</li></ul><h2 id=websphere-user-group>WebSphere User Group</h2><p>Finally, we took this to the latest WebSphere User Group (WUG) which was held in IBM’s Southbank offices.</p><p>[[Game On stand at the WUG]]</p><p>We had lots of people stop by and ask us a whole range of questions, for example:</p><ul><li>So what are microservices?</li><li>Why is Liberty a good fit for microservices?</li><li>You’ve done, what!?! with a text adventure…</li><li>Can you take the car off the blocks so that I can drive it around ? (which was fun because, of course, we said yes)</li></ul><p>Game On! gives us a really great context within which to answer these questions. The fact that it’s available online and the code is in GitHub means that you can write your own rooms and learn about microservices with Liberty whenever and wherever you want.</p></section></article><nav class=prev-next><div class=nav-left></div><div class=nav-center><a href=/blog/>Blog</a> | <a href=/archive/>Archive</a></div><div class=nav-right><a href=/2016/09/29/gameon-at-javaone.html title="Next: Game On! at JavaOne 2016">Next</a></div></nav><footer class=foot><div id=copyrights>&#169; 2016-2021 under terms of the Apache License 2.0.</div><div>Follow us:
<a target=_blank href=https://twitter.com/gameontext title="Follow @gameontext"><i class="fa fa-twitter" aria-hidden=true></i></a></div></footer><script type=application/javascript>var doNotTrack=false;if(!doNotTrack){window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;ga('create','UA-90113653-2','auto');ga('send','pageview');}</script><script async src=https://www.google-analytics.com/analytics.js></script></body></html>
</code></pre><h2 id=the-final-picture>The final picture</h2><p>At a high level, this is how we had all the services talking to each other:</p><p>[[GameOn Demo Architecture]]</p><p>This architecture shows:</p><ul><li>A virtual machine with 7 Docker containers, each running an instance of Liberty</li><li>A polyglot environment with both node.js and Liberty runtimes</li><li>A Raspberry Pi running Liberty, with 4 deployed applications</li><li>Service re-use; being able to drive the car, or take pictures, through Game On! or using a second web interface</li></ul><h2 id=websphere-user-group>WebSphere User Group</h2><p>Finally, we took this to the latest WebSphere User Group (WUG) which was held in IBM’s Southbank offices.</p><p>[[Game On stand at the WUG]]</p><p>We had lots of people stop by and ask us a whole range of questions, for example:</p><ul><li>So what are microservices?</li><li>Why is Liberty a good fit for microservices?</li><li>You’ve done, what!?! with a text adventure…</li><li>Can you take the car off the blocks so that I can drive it around ? (which was fun because, of course, we said yes)</li></ul><p>Game On! gives us a really great context within which to answer these questions. The fact that it’s available online and the code is in GitHub means that you can write your own rooms and learn about microservices with Liberty whenever and wherever you want.</p></section></article><nav class=prev-next><div class=nav-left></div><div class=nav-center><a href=/blog/>Blog</a> | <a href=/archive/>Archive</a></div><div class=nav-right><a href=/2016/09/29/gameon-at-javaone.html title="Next: Game On! at JavaOne 2016">Next</a></div></nav><footer class=foot><div id=copyrights>&#169; 2016-2023 under terms of the Apache License 2.0.</div></footer></body></html>
Loading

0 comments on commit 3f61918

Please sign in to comment.