Recent Posts
Archives

Posts Tagged ‘Reactive’

PostHeaderIcon [DevoxxFR2015] Reactive Applications on Raspberry Pi: A Microservices Adventure

Alexandre Delègue and Mathieu Ancelin, both engineers at SERLI, captivated attendees at Devoxx France 2015 with a deep dive into building reactive applications on a Raspberry Pi cluster. Leveraging their expertise in Java, Java EE, and open-source projects, they demonstrated a microservices-based system using Play, Akka, Cassandra, and Elasticsearch, testing the Reactive Manifesto’s promises on constrained hardware.

Embracing the Reactive Manifesto

Alexandre opened by contrasting monolithic enterprise stacks with the modular, scalable approach of the Reactive Manifesto. He introduced their application, built with microservices and event sourcing, designed to be responsive, resilient, and elastic. Running this on Raspberry Pi’s limited resources tested the architecture’s ability to deliver under constraints, proving its adaptability.

This philosophy, Alexandre noted, prioritizes agility and resilience.

Microservices and Event Sourcing

Mathieu detailed the application’s architecture, using Play for the web framework and Akka for actor-based concurrency. Cassandra handled data persistence, while Elasticsearch enabled fast search capabilities. Event sourcing ensured a reliable audit trail, capturing state changes as events. The duo’s live demo showcased these components interacting seamlessly, even on low-powered Raspberry Pi hardware.

This setup, Mathieu emphasized, ensures robust performance.

Challenges of Clustering on Raspberry Pi

The session highlighted configuration pitfalls encountered during clustering. Alexandre shared how initial deployments overwhelmed the Raspberry Pi’s CPU, causing nodes to disconnect and form sub-clusters. Proper configuration, tested pre-production, resolved these issues, ensuring stable heartbeats across the cluster. Their experience underscored the importance of thorough setup validation.

These lessons, Alexandre noted, are critical for constrained environments.

Alternative Reactive Approaches

Mathieu explored other reactive libraries, such as Spring Boot with reactive Java 8 features and async servlets, demonstrating versatility beyond Akka. Their demo included Gatling for load testing, though an outdated plugin caused challenges, since resolved natively. The session concluded with a nod to the fun of building such systems, encouraging experimentation.

This flexibility, Mathieu concluded, broadens reactive development options.

Links:

PostHeaderIcon [DevoxxFR2012] — Rev:2, Add twitter handle

ALTER TABLE speaker ADD COLUMN twitter varchar(255);


These scripts run automatically on startup, supporting continuous delivery.

## RESTful API Development
James Ward constructs JSON endpoints:

public class ApiController extends Controller {
public Result speakers() {
List speakers = Speaker.find.all();
return ok(Json.toJson(speakers));
}
}


Play’s `Json.toJson` uses Jackson for serialization, with configuration in `application.conf`:

play.modules.enabled += “play.modules.reactivemongo.ReactiveMongoModule”


## Form Handling and Validation
Nicolas demonstrates form binding:

public class FormsController extends Controller {
static Form speakerForm = Form.form(Speaker.class);

public Result create() {
    Form<Speaker> filled = speakerForm.bindFromRequest();
    if (filled.hasErrors()) {
        return badRequest(views.html.create.render(filled));
    } else {
        Speaker speaker = filled.get();
        speaker.save();
        return redirect(routes.Application.index());
    }
}

}


HTML forms use Play’s template engine:

@form(routes.FormsController.create()) {
@inputText(speakerForm(“name”), ‘_label -> “Name”)
@inputText(speakerForm(“twitter”), ‘_label -> “Twitter”)

}


## Frontend Development with HTML5 and JavaScript
Guillaume Bort integrates Twitter Bootstrap and jQuery for responsive design, demonstrating real-time features with WebSockets:

public class StreamController extends Controller {
public WebSocket updates() {
return WebSocket.whenReady((in, out) -> {
// Push updates
});
}
}


## Cloud Deployment to Heroku
James Ward executes deployment:

heroku create devoxx-play-demo
git push heroku master
heroku addons:create heroku-postgresql


Play’s `Procfile` declares the startup command:

web: target/universal/stage/bin/conference-app -Dhttp.port=${PORT}
“`

Implications for Modern Web Development

The presenters conclude that Play 2.0’s integrated toolchain and cloud-ready architecture dramatically accelerate development cycles while producing applications that scale effortlessly in elastic environments.

Links: