Tag Archives: microservices

WSO2 Microservices Server: Microservices in Ten Minutes!

Before we begin, I’d like to start by saying that this is not an introduction to microservices. Much has been written about the microservices paradigm and monolithic hell. If what you’re after is a good introduction, look no further than NginX’s introduction to microservices or Microservices: a definition to this architectural term by Martin Fowler and James Lewis.

Instead, we’re going to talk about WSO2 Microservices Server. At WSO2, we’ve put together a lightweight, high-performance microservices runtime with a  simple programming model for developing Java based microservices. It’s new, starts in under 300 milliseconds, and of course, integrates with our Data Analytics Server for additional insight. Let’s get started.

Hello, World

Let’s run through the process of getting the most basic sample running. This is literally a Hello World.

Firstly, make sure you have Java 8 and Maven installed. Then grab the zip from Github.

This folder is basically <MSS_HOME>. Make sure you mount the pom.xml into your Java IDE of choice. Then navigate to <MSS_HOME>/samples/hello_world. If you haven’t fired up your command prompt already, do it and type mvn package.

This’ll take a short while, and when you’re done you’ll have a helloworld*.jar. Run it.

From the target directory, use java -jar.

Congratulations! You’ll see a Netty listener starting up. You’ll also see that the Microservices Server has started up – in so many milliseconds.

It’s alive!

Of course, you need to test it. Use the curl command:

curl -v http://localhost:8080/hello/wso2 (depending on where you’ve put it)

For windows users, try http://www.confusedbycode.com/curl/. You can also forgo Curl entirely and use HTTPie.

You should get a response similar to the following:

* Adding handle: conn: 0x7fc9d3803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* – Conn 0 (0x7fc9d3803a00) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 8080 (#0)
*   Trying ::1…
* Connected to localhost (::1) port 8080 (#0)
> GET /hello/wso2 HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: */*
< Content-Length: 10
< Connection: keep-alive
<
* Connection #0 to host localhost left intact
Hello wso2

What happens here?

Open up the HelloService class.

import javax.ws.rs.GET;

import javax.ws.rs Path;

import javax.ws.rs Pathparam;

That’s JAX-RS, which comes in handy when creating RESTful web services.

@Path(“/hello”)

public class HelloService{
@GET
@Path (“(/name)”)
public String hello(@PathParam(“name”) String name) {
return “Hello “ + name;
}
}

Here we have a simple class acting as a REST endpoint. This is what says hello.
How does this get started? By something like this:

public class Application (
public static void main(String[] args) {
new MicrosevicesRunner(8080)
.deploy(new HelloService())
.start();
}

If you want to pass services through different ports, all you need to do is modify the arguments passed to MicroserviceRunner(). MicroservicesRunner(7888, 8888) will start up two Netty Listeners on port 7888 and 8888 respectively.

Now for a second exercise: stockquotes.

In the same manner as before, enter the <MSS_HOME> folder, navigate to samples, and enter the stockquotes-services folder. Technically, this sample is meant to demonstrate the use of @Produces and @Consumes annotations for bean conversion. We’re going to use it to see how a simple way of sending a POST message to our service.
Use mvn package.

curl -v http://localhost:8080/stockquote/GOOG

You should get an output along these lines: (“symbol”: “GOOG”, “name”: “Alphabet Inc.”: “last”:652.3, “low”:657.81,”high”:643.15”)
We’ve just pulled data that’s in our stockquote service.
What if we wanted to add data, say, the stock price of another company? We can add it via a POST message using the same format.

curl -v -X POST -H “Content-Type:application/json” -d ‘{“symbol”:”BVMF”,”name”: “Bovespa”,”last”:149.62,”low”:150.78,”high”:149.18,”createdByHost”:”localh ost”}’ http://localhost:8080/stockquote

This command will save a new symbol into the Stock Quote Service.

Congratulations! You’ve successfully used Java 8 and Maven for setting up the WSO2 Microservices Server and building our services and samples, executed Microservices with a basic java -jar approach and seen how easy it to to deploy a REST Service onto our Microservices Server.
For more exploration, drop by our documentation page for more samples and check out our more detailed slideshow.

Have You Checked Out the WSO2 Machine Learner Yet?

WSO2 Machine Learner is the latest addition to the WSO2 product stack. Or, to be precise, one of the latest additions: Machine Learner only held the crown for a few weeks before WSO2 Data Analytics Server become the new kid on the block.

Nevertheless, Machine Learner is something we’re particularly proud of. As you no doubt guessed, it’s a product meant for predictive business analytics: by building models and running data through them, it allows one to quite literally peek into possible futures.

Why is this important? Well, machine learning is rapidly becoming the new frontier for businesses. We’ve gone from educated guesses to dedicated analytics: now we’re trying to predict the future.

“I keep saying the sexy job in the next ten years will be statisticians. People think I’m joking, but who would’ve guessed that computer engineers would’ve been the sexy job of the 1990s?” – Hal Varian, Chief Economist at Google

Hal Varian expects statisticians to be the next sexy job because of the sheer amounts of data and intelligence that companies need to chew through these days.  At WSO2, we expect machine learning to be an integral part of what makes that job sexy. And useful.

Done right, machine learning can easily replace a small army of statisticians – especially when it comes to enterprise big data. The world isn’t (yet) at the level where we can recreate a Minority Report for businesses, but there’s a lot of work that’s gone into this space. If you don’t know the field, you should: we’d recommend this short and beautifully designed Visual Introduction to Machine Learning, courtesy of R2D3.

If you know the field, you can skip the above and go directly to what Nirmal Fernando has to say. Nirmal leads the team working on the project, and his blogpost on ML gives a quick, concise breakdown of what WSO2 Machine Learner is capable of. Part of the challenge of predictive analytics is presenting the data intelligently, something we’ve paid careful attention to with WSO2 ML.

After that, you should probably check out what Srinath Perera, our Vice President of Research, has to say: he’s written a post called “WSO2 Machine Learner: Why Would You Care?” on his personal blog. This talks about how ML is built, and the uses you can put it to.

As you can see, ML completes our analytics offerings – we now offer batch, real-time, interactive and predictive analytics, and all of these components tie into each other beautifully for creating end-to-end analytics solutions for your business.

Of course, we have plans for making Machine Learner more powerful: we plan to add neural networks, algorithmic recommendation, anomaly detection, and more – as the product evolves, we’ll keep pushing out updates.

You can jump in and check this all out for yourself, of course! Machine Learner is free and open source. The Getting Started guide in our documentation will tell you everything you need to know to get a Machine Learner instance off the ground. Supun Setunga’s cooked up a detailed post on how you can set up that very first predictive model.

Download Machine Learner here, and you’re good to go. Set up your models right and you can peek into the future without actually having to go at 88 miles an hour in an old DeLorean. What’s not to like?

PS: If you’d like to call for support, or suggest features, don’t hesitate to contact us. We welcome bug reports, too!