We've been talking about the new NixMash Microservice Application Listreme which filters Twitter User List Tweets by various criteria. You'll find it at listreme.com. Here are other NixMash posts on it.
In a distributed architecture you have several modules which make up the application. In this post we'll be looking at how to retrieve various Java Data Types in a Web client from a Microservice named TwitterService.
Examples of Needing Data Types from a Microservice
You may ask, when do you need to retrieve Booleans, Integers and other Data Types directly from a Microservice? Here's an example which we'll walk through in this post. On the Web User List Tweets Page we are polling the Microservice to let the user know when there are new tweets and how many. On the page it looks like this.
The TwitterService Resource Output
Here's the method which produces the Integer value in the Microservice.
Notice on the Microservice side we're producing MediaType.TEXT_PLAIN. That would look like this if queried in a Web Browser. (Notice the "4"…)
On the Web Client
In getRestNewTweetCount() we call a reusable method to retrieve Integers from our REST Microservice. Typically we would use Jersey JAX-RS to create a REST Client then process the Response object. To retrieve simple Java Data Types an InputStream to the URL is a much cleaner approach as you can see. IOUtils is a member of the Apache Commons.IO library.
Back on the web page we see "There are 4 new News tweets!"