Posted by Editor | 2/24/2016 11:31:00 pm | 0 comments »
Service oriented architecture(SOA) separated the business logic from presentation layer, then comes IoT(Internet of Things) which need the services to be served to multiple clients such as web, Mobile and middle-ware applications. Also, the Cloud Computing Architecture made application developers life easier by providing highly scalable and reliable infrastructure.

But when the business grows, business complexity also grows and the services exposed also becomes non-maintainable. Your code becomes too complex; continuous delivery, testing, scaling - all becomes difficult. Micro-service architecture solves this problem by breaking down business functionalities into small, highly scalable, loosely coupled services called micro-services which runs in parallel.

Since the services are completely independent, the code will be clean, testable and maintainable. Also, the developers can independently work on the services, can independently test the features, can do continuous delivery without affecting other running services(must be backward compatible). When it comes to scalability, micro-service architecture gives you complete freedom in scaling individual services on increase in load.

No doubt, micro-service architecture is the future of enterprise software development. You can build micro-services in any technology you like and deploy them on your favorite application server running on private or public cloud(aws, azure, google cloud etc.). Also some cloud service providers provides Platform as a Service(PaaS) where they will take care of the capacity provisioning, load balancing, auto-scaling, and application health monitoring(e.g. Amazon Elastic Beanstalk, Google App Engine etc.). Amazon went ahead and provided one more platform where you don't even have to think of infrastructure or platform at all, all you need to do is, write your code and upload to aws! Yes, aws Lambda makes it possible to run a piece of code driven by events or by HTTP requests. Lambda takes care of provisioning and managing the servers and also takes care of auto-scaling, monitoring and logging.

In this article, you will learn how to build highly scalable micro-services using Java 8, AWS Lambda and AWS API Gateway. You should have an active AWS account, basic knowledge on various AWS services, understanding of RESTful(REpresentational State Transfer) services and of course basic Java coding skills.

DynamoDB Database Setup



First we will setup a DynamoDB table where we can insert, update delete records. Go to DynamoDB section in aws console and create a table named "product". Add "sku" as primary key(partition key), leave all other settings as default and click on "Create". Now let's insert a new item, for this, go to Items tab and click on "Create Item". Select "Text" from the drop-down and paste the below json content in the area provided, then click on "Save".

{
  "Sku": "SKU00001",
  "Name": "Apple iPhone 6",
  "ImageUrl": "http://www.appleg.com/images/iphone6.png",
  "ShortDescription": "Short Description",
  "LongDescription": "Long Description.",
  "Price": "699.99"
}

Writing business logic


We will simply read product details from DynamoDB and return the result back to the caller. Create a maven project and add dependencies for lambda and dynamodb, your pom.xml will like like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
        http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.texient</groupId>
  <artifactId>ecommerce</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>ecommerce</name>
   <dependencies>
   <dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-lambda-java-core</artifactId>
  <version>1.1.0</version>
 </dependency>
 <dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk-dynamodb</artifactId>
  <version>1.10.54</version>
 </dependency>
 <dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.4.3</version>
 </dependency>
  </dependencies>
</project>

Now, we need the domain class, say Product.java as below:

package com.texient.ecommerce.model;

public class Product {
 
 private String sku;
 private String name;
 private String shortDescription;
 private String longDescription;
 private String imageUrl;
 private String price;
 
 public String getSku() {
  return sku;
 }
 public void setSku(String sku) {
  this.sku = sku;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getShortDescription() {
  return shortDescription;
 }
 public void setShortDescription(String shortDescription) {
  this.shortDescription = shortDescription;
 }
 public String getLongDescription() {
  return longDescription;
 }
 public void setLongDescription(String longDescription) {
  this.longDescription = longDescription;
 }
 public String getImageUrl() {
  return imageUrl;
 }
 public void setImageUrl(String imageUrl) {
  this.imageUrl = imageUrl;
 }
 public String getPrice() {
  return price;
 }
 public void setPrice(String price) {
  this.price = price;
 }

}

Let us implement the business logic in a lambda request handler class as follows:

package com.texient.ecommerce.service;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.texient.ecommerce.dynamodb.ProductDelegate;
import com.texient.ecommerce.model.Product;

public class GetProductImpl implements RequestHandler{
 
 public Product handleRequest(Product product, Context context){
           context.getLogger().log("Input: " + product.getSku());
           product = ProductDelegate.get(product.getSku());
           if(product!=null) {
         context.getLogger().log("Returning product details");
         return product;
           }else{
         throw new RuntimeException("404");
           }
    }
 
}


Creating a Lambda Function



Let's create a Lambda function which will execute the handler method we implemented earlier via API Gateway. In REST world it is a GET endpoint, say /product/{sku} which will return the product details of {sku}. Go to Lambda tab in aws console and click on "Create a Lambda Function". Select "microservice-http-endpoint" blueprint, provide name as "GetProduct" and select "Runtime" as "Java 8". Provide S3 url(or upload jar file) for your Lambda function code, enter handler as "com.texient.ecommerce.service.GetProductImpl::handleRequest" and select a role which has complete access to S3, DynamoDB and Lambda. Leave all other fields as default and click on "Next".

On next page we will setup the API endpoint, provide API name as "ProductService", Resource anme as "/product", method as "GET", stage as "Prod" and security as "Open"(for time being). Click "Next", review the details and click "Finish". This will create a new Lambda function "GetProduct" and an end point which points to the newly created Lambda function.


Setting up API Gateway


If you open the API Gateway tab in aws console, you will see an API already created for you by the "microservice-http-endpoint" blueprint. Click on /product and then Create Resource button, provide "Sku" as resource name and {sku} as path param. Create a "GET" method under /product/{sku}, click on it and then in the Integration Request, select integration type as Lambda Function and select the lambda function you created in the earlier step. Add a new mapping template "application/json", then fill the template with the below json:

{
    "sku" : "$input.params('sku')"
}

Also you can use the below shortcut to map all your query parameters to Lambda parameter "query":
{
    "query": "$input.params().querystring"
}

We are all set to test the API end point. On the left side you will see a "Test" button, click on it and provide "SKU00001" for sku and hit "Test" button. A console will appear on the right with the log, where you can see the response body and response status. If you have followed the steps as mentioned above, you will get a 200 response with the product details in the response. In the log section you will see the debug log, input to the Lambda function, and the transformed output.

Publish the API


So we have an API endpoint pointing to the Lambda function; to invoke it from a REST client, you need to deploy the API. On top left there is a "Deploy API" button, hit on it, the API is deployed and you will get an endpoint similar to https://blabla.execute-api.us-west-2.amazonaws.com/prod/. You can now do a GET for sku SKU00001 by invoking the url https://blabla.execute-api.us-west-2.amazonaws.com/prod/product/SKU00001.


Conclusion


We implemented and deployed a highly scalable RESTful micro-service with AWS Lambda and API Gateway without even thinking of application servers nor on load balancers. AWS takes care of provisioning of compute units and auto-scaling. Also, aws provides options to cache the responses, which heavily decreases the processing time and thus response time. In our test, we noticed initial request taking more response time, subsequent requests are served incredibly fast, could be due to provisioning of resources. Also you will have to do an error mapping to return correct HTTP status code, which is completely manual. Apart from these, we feel API Gateway + Lambda stack is a super simple but extremely powerful tool for building enterprise level micro-services. For existing services, you can simplify migration by importing the Swagger documentation, API Gateway creates all end points and models defined in the documentation, you just need to create Lambda functions and associate them with the end points.












Continue reading...

Posted by Editor | 1/12/2016 09:35:00 pm | 0 comments »
My Samsung Smart TV recently started behaving strangely, I can change the channels, increase/decrease volume, access TV menu and change settings, no issue at all. The problem starts whenever I start the Samsung Smart Hub app!

If I open the browser on TV, the pointer moves a little bit and stops responding for few seconds. Again it moves a little bit and then stops, really irritating. Same with YouTube app, the pointer is totally unresponsive but I can use the arrow keys to control the video or to type using the on-screen keyboard.


I did a lot of research, many asked to go close to the TV and operate the remote, some suggested to remove the batteries, then while holding the power button, replace the battery by pressing and holding the power button, but none worked for me. Also I tried turning the power off for few minutes, then turn it on, also did factory reset, nothing worked.

I read somewhere(in CNET forum) it is a hardware/firmware issue which Samsung could not fix till now but in my case it was working before with no issue at all, even there were no software updates recently, so definitely it is not an existing hardware/software issue. Some people reported, their issue got fixed when they connected the TV to internet via Ethernet, claiming the bandwidth used by the remote is conflicting with the wifi etc, still the question in my mind was, how this was working before?

Finally I decided to contact Samsung customer support, just before dialing, my wife suggested putting new batteries in the remote, I removed the Korea made "Rocket" batteries and put brand new Energizer batteries, you won't believe, the remote started working as before!!!

So, it was all because of weak batteries, the pointer was not responding. Some people reported the remote responds when the move close to the TV, this confirms weak signal from the remote due to weak batteries. Not sure how it worked for few when they connected their TV directly via Ethernet, could be they were operating the remote very close to the TV while testing. Anyway, if you are facing similar issue, first replace your remote batteries with new high power batteries and check if it is working, if not contact the customer support.
Continue reading...

Posted by Editor | 10/06/2015 11:20:00 pm | 0 comments »

Follow the below steps if you want to preserve the namespace prefix values consistent.

First define a namespace prefix map, say JAXBNamespacePrefixesMap as below:

<util:map id="JAXBNamespacePrefixesMap">
   <entry key="http://www.texient.com/mail" value="ns1" />
   <entry key="http://www.texient.com/account" value="ns2" />
   <entry key="http://www.texient.com/contact" value="ns3" />
   <entry key="http://www.texient.com/address" value="ns4" />
   <entry key="http://www.texient.com/category" value="ns5" />
</util:map>

Now set this map as namespacePrefixes in JAXBElementProvider.

<bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
   <property name="jaxbElementClassMap" ref="JAXBElementClassMap" />
   <property name="marshallAsJaxbElement" value="true" />
   <property name="unmarshallAsJaxbElement" value="true" />
   <property name="collectionWrapperMap" ref="JAXBElementClassMap" />
   <property name="namespacePrefixes" ref="JAXBNamespacePrefixesMap" />
</bean>

In the server configuration you will have jaxbProvider as a provider.

<jaxrs:server id="CXFService" address="/" >
   <jaxrs:extensionMappings>
      <entry key="json" value="application/json" />
      <entry key="xml" value="application/xml" />
   </jaxrs:extensionMappings>
   <jaxrs:serviceBeans>
      <ref bean="CXFServiceBean"/>
   </jaxrs:serviceBeans>
   <jaxrs:providers>
         <ref bean="jaxbProvider" />
         <ref bean="jsonpProvider" />            
    </jaxrs:providers>
    <jaxrs:inInterceptors>
       <ref bean="jsonpInInterceptor"/>
    </jaxrs:inInterceptors>
    <jaxrs:outInterceptors>
        <ref bean="jsonpOutInterceptor"/>
      </jaxrs:outInterceptors>         
</jaxrs:server>

That's it! You will see the namespace prefix as defined in the mapping.

<ns1:person xmlns:ns1="http://www.texient.com/mail" xmlns:ns2="http://www.texient.com/account" xmlns:ns3="http://www.texient.com/contact" xmlns:ns4="http://www.texient.com/address" xmlns:ns5="http://www.texient.com/category">
   <ns3:account>
      <ns4:address>Your address</ns4:address>
      <ns5:category>Customer</ns5:category>
   </ns3:account>
</ns1:person>
Continue reading...

Posted by Editor | 8/05/2015 10:53:00 am | 0 comments »
In cities owning an independent house with some garden space is only a dream for most of the middle and small class citizens. You are forced to buy a two or three bedroom apartment with little open space called 'balcony'. Still you can fulfill your dream of having your own vegetable garden by efficiently utilizing the balcony.

What you need?

Red Spinach - Multiple Plants in One Pot
As a beginner you just need little space in balcony, few vegetable pots, vegetable seeds and soil mix. Once you have a basic setup you can move to advance level such as add vertical gardening, drip irrigation etc.

How to select vegetable pots?

Malabar Cucumber
There are different types of pots available in the market, you need to choose the one best suitable for balcony gardening. Since you don't have much space for your garden, you should go for small ones but should look good. Terra Cotta containers are normally good for plants but won't be a good option for balcony as those are heavy, cracks easily if not handled carefully. There are plastic containers which looks similar to Terra Cotta containers but are very light, good looking and hence a better option for balcony gardening. Also you can use plastic grow bags which are very cheap but not durable and may not give a good looking balcony. There are other cheaper options like thermocol containers, empty tin containers etc.

Filling with soil mix

Make sure to put drainage holes before filling the pot with soil mix. You will get organic soil mix from nearby stores or even eCommerce shops such as Amazon, Flipkart etc. Now fill soil mix up to 80% of the pots and keep it at positions where maximum sunlight is available. Optionally you can add a think layer of sand at the bottom of the pot to make the drainage flow smooth.

Sowing the seeds

Country Tomato grown in balcony
Sow only one variety of seed in one pot, scatter seeds evenly, then add a thin layer of soil on top of the seeds. Water the pots gently only to moisten the soil, don't over water the pots. Germination takes one to five days, be patient. Also not all seeds germinates, so seed accordingly.

Transplantation

Pumkin
Once the seeds germinates and develops two to three leaves, its time to transplant them to individual pots. Gently take out the plants one by one and plant them on the new pots. Keep 2-3 inches space between plants(depends on the plant type).

Caring your plants

Curry Leaves in Balcony
Water and sunlight is must for vegetable plants. Water the plants regularly, if possible in the morning and evening. Never over water plants. Move the pots to places where more sunlight is available. Fertilize the plants on a weekly basis.

Drip Irrigation

Balcony garden with Drip Irrigation
You will get cheap drip irrigation DIY kits from the market, normally costs Rs.500 - Rs.1000 for 20 plants. There are many advantages of Drip-irrigation, and the most important is it saves lots of water. Another important factor is it saves time if your garden is big and you are a busy person. Also it becomes useful when you want to stay away from home for couple of days and want to keep watering your garden.
Continue reading...

Posted by Editor | 7/17/2015 07:16:00 pm | 2 comments »
Are you a freelancer earning money in India by writing blogs or by doing search engine optimization(SEO) or by data entry work? If the answer is yes, you are liable to pay income tax and service tax in India provided you are exempted to pay taxes under various acts under income tax and service tax sections.
 
Since you are not earning salary, the income earned from the freelancing should be filed under "Profits or Gains of Business or Profession" and you can use either ITR-4 or ITR-4S for filing tax returns.
 
Interesting part is, you do not need to show the whole money you earned via freelancing as income, the income is the revenue earned minus the annual expenses minus annual depreciation of the assets you used for freelancing, for example, laptop, printer, modem etc. You can consider electricity charges, rental, phone charges, internet charges etc. as annual expenses and those can be deducted from the income.
 
You can start filing your tax return once you are done with the income calculation for that financial year. If you do not have an account with Income Tax India, first create one by clicking incometaxindiaefiling.gov.in then, login with your user id and password. Do not forget, your user id is your PAN number.
 
Once logged in, click on the e-File link. Now you can select the ITR form, in our case ITR-4S and the assessment year. Address, you can choose to get from PAN database. If the current address is different from that of with PAN database, choose "New Address". If you already have a digital signature choose "YES" for "Do you want to digitally sign?". If you are not sure what digital signature is, don't worry, simply select "NO". Now proceed to next page.
 
Next page is for personal details, fill all mandatory fields carefully and proceed to next step.
 
This is where you provide your freelancing business details. You need to provide the nature of the business you are doing, the revenue and income along with other financial particulars of the business. For "Nature of Business", you select "709 - IT. enabled services, BPO service providers". Now under "Details of Income from Business" section, provide E1(Gross Turnover) and E2(Total Income). The form will automatically calculate E4(Income chargeable under Business). Fill "Financial Particulars of the Business" and proceed to next page.
 
This section automatically populates all tax deduction details(TDS), if there are any. Fill the appropriate section if you have any tax paid in the applicable financial year. This includes the tax deducted by bank towards interest against fixed deposits(it is mandatory to deduct tax for interest over Rs. 10,000). Save the form and proceed to next step. This page shows the summary of the income and exemption details along with the tax paid and payable details. If you have paid excess tax, the refund amount also is given at section D19. In D21 provide your bank account details so that the refund if any will be wired to this account automatically.
 
Verify the details once again and if you are sure all the information provided is correct, click on "Submit" which will upload the form to Income Tax Department for verification. You can download the ITR-V by going to "My Account" -> e-Files Returns/Forms.
 
Click the acknowledge number to get the acknowledgement download link. Now download the form, and open it, provide the password which is lower case PAN number + your date of birth in numerical format, say abcde31121970.
 
 
Now take a print of ITR-V, sign at the bottom and send it to the address mentioned at the bottom by normal post. You will get a confirmation
 

Disclaimer

All data and information provided on this site is for informational purposes only. The material contained on this site and on the associated web pages is not intended to be advice on any particular matter. Subscribers and readers should seek appropriate professional advice before acting on the basis of any information contained in this site. No Advice or information, whether oral or written obtained by you from Texient.com or through the service shall create any warranty/liability against Texient.com. The authors, employees and owners of this site expressly disclaim any and all liability to any person, whether a subscriber or not, in respect of anything and of the consequences of anything done or omitted to be done by any such person in reliance upon the contents of this site and associated web pages.
Continue reading...

Posted by Editor | 7/17/2015 12:05:00 pm | 2 comments »

You might have seen a cute dinosaur whenever you try to access a webpage on Chrome browser but not connected to internet. There is an addictive game hidden on that page, a never-ending running game!

How to play this running game?

If you are on a PC, make sure your PC is not connected to internet, open Chrome browser and access any webpage say, google.com. Now Chrome will display a page saying you are offline with a dinosaur image. Simply press the space bar and here you go, the game starts!!!

Hitting the space bar again will make the dinosaur jump so that it can escape from the obstacles.

On mobile phones, the game starts on tapping the dinosaur. Tap again to keep the dinosaur running until it hits the Cactus. You can restart the game as many times as you want.

You earn points for the distance you covered and for each high score the player is greeted with a beep. High score is erased on exit or refresh of the page.

Some facts about this game

The dinosaur you see on this game is T-Rex(Tyrannosaurus rex), one of the largest land carnivores of all time lived 65 million years ago. T-Rex has short arms with only two fingers, makes it difficult to grab things. What this image represents is that Chrome is having trouble reaching out to the internet. Why a T-Rex? Could be because you are living in the dinosaur age with no internet at all!

You can reduce your frustration by playing this game if there is an internet outage instead of staring at the offline page as in Internet Explorer.

The T-Rex image and sound designs were done by Google Chrome designers Mr.Sebastien Gabriel, Alan Bettes and Manuel Clement where the game was entirely coded by Mr. Edward Jung.

Want to know more on the implementation? Here you can grab the source code of the game: Chromium Code Reviews. The game is written in JavaScript, file offline.js contains the core logic.

Liked the game? Share your feedback below.

Continue reading...




Recommended products