Saturday, 10 September 2016

First apache camel application

Apache Camel :- Is built on top of enterprise integration patterns which does all type heavy lifting working and focusing developers on code logic.It is mainly involved in integration of different services.Like moving a file from location to another by transforming/enriching content of file.

Pre-requisite :- Down load camel jars and have them in build path.

Step1 :- Create a plain java project

Main application :- Where we create camel context and add routes

package com.java.firstCamel;

import org.apache.camel.*;
import org.apache.camel.impl.DefaultCamelContext;

public class MainApp {

public static void main(String args[]) {
RouterBuilder routerBuilder = new RouterBuilder();
CamelContext camelContext = new DefaultCamelContext();
try {
camelContext.addRoutes(routerBuilder);
camelContext.start();
Thread.sleep(5 * 60 * 1000);
camelContext.stop();
} catch (Exception e) {
e.printStackTrace();
}
}

}

Route Builder :- Core logic for route builder to move file form one place to another.

package com.java.firstCamel;

import org.apache.camel.builder.RouteBuilder;

public class RouterBuilder extends RouteBuilder {

@Override
public void configure() throws Exception {
// TODO Auto-generated method stub
from("file:/C:/Location1/krishna").process(new LogProcessor()).bean(new Transformer(), "transfromMessage")
.to("file:/C:/Location12");

}

}

Transformer :- Core logic for transforming or modifying in coming data.

package com.java.firstCamel;

public class Transformer {

public String transfromMessage(String message) {
System.out.println("Tranformation executed");
return message.toUpperCase();
}
}

LogProcessor :- To log and verify the result is proper or not

package com.java.firstCamel;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class LogProcessor implements Processor {

@Override
public void process(Exchange exchange) throws Exception {
// TODO Auto-generated method stub
System.out.println("Executing log processor :- " + exchange.getIn().getBody(String.class));

}

}


Thursday, 8 September 2016

JMS with active MQ without context loookup

Active MQ :- Is a middle-ware framework where messages are handled in reliable manner without any loss of information. Mainly utilized for distributed environment where information from one JVM need to be passed to another JVM. It has two types of mechanism point to point and publish subscribe mechanism.

Step 1) Download latest active mq.
http://activemq.apache.org/activemq-550-release.html

Step 2) Set JAVA_HOME variable till JDK or JRE.

Step 3) Navigate till bin folder 'C:\apache-activemq-5.5.0-bin\apache-activemq-5.5.0\bin' and start it
using 'activemq'command for previous versions. In newer versions use 'activemq start'.

Step 4) http://121.0.0.1:8161/admin to access the admin console.

Step 5) Now create a dynamic web application and create sender and receiver classes to produce and consume message.

Sender :-  Run sender it will use default broker url and creates a queue with name ''PRACTICEQUEUE" and sends a message.




Receiver :- It receives message from default broker URL("failover://tcp://localhost:61616") and prints out to console. 


  

Tuesday, 6 September 2016

Basic linux commands

Linux :- Its est open source operating system available in outside world. I has many file systems like ext4 etc unlikely to windows(FAT32/NTFS)

. -> Represents current directory in Linux
.. -> Represents parent directory


killall - Will force fully kill the application with no traces left. 'An instance of firefox is already open' is a real time example to use the command(Usage- killall thunar)- In this command i am closing file manager.

ls - Will list all files in current directory(Usage- ls) in addition to it 'ls -r' lists all sub directories also.'ls -all' displays the permissions also. 'ls -a' to see all hidden files.

touch - will create files (Usage - touch file1.txt file2.txt) - creates two files. If you want to create one file then you can use graphical console else you need to created many files then 'touch' is the best command.When you touch files it will change the timestamp of files which is very helpful for backup files.

which - this command is used to find where does the current installed application is.(Usage- which google-chrome)

ping- To check whether a particular site is reachable from your system(Usage - ping www.google.com -c 3)

cat - It opens up text files to view the information in it(Usage - cat /etc/fstbs). If the file is very big file this command might not be appropriate. Advanced usage  - cat /etc/fstbs | more.'cat > test.text' will provide a provision to add more or edit the file. 'cat file1 file2 > file3' to form a new file 'file3'.

less - More advanced command compared to above where there are many privileges for page navigation.(Usage - less /etc/fstbs)

blkid - Lists all drives (Usage - sudo blkid)

su - simulate the login as other user (Usage - su krishna)- will log me into krishna machine. By typing exit you can logout.This provides an alternative way of 'switching users' via GUI.

reboot - It wil restart the system (Usage - su reboot)

shutdown - Will shutdown the system (Usage - su shutdown -h 15)- It will shutdown the machine after 15 mins, 'su shutdown -c' will ignore the previous command if you change your mind regarding shutdown.

cd - change directory.

date - displays current date (Usage - date)

cal - current month calendar(Usage - cal 2015) - displays full 2015 calendar

uptime - will display how many user ave logged in currently (Usage - uptime)

w - provides who all have been logged in (Usage - w)

whoami - displays which user is currently logged into the terminal (Usage - whoami)

uname -a - displays kernel information (Usage - uname -a)

mkdir - to create directory (Usage - mkdir vfx)

pwd - displays what is your current directory. So that you can navigate to required directory.

ifconfig - Displays current ip information

mv - to move the file to a different directory (Usage - mv filename directoryName). This can be used for rename also (Usage - mv oldfFileName newFIleName)

cp - copy file to a different directory (Usage - cp filename directoryName)

rm - Is used to remove directory

rm -r - This command is used to remove directory (Usage - rm -r directoryName)

man - manual which provides help to construct the command (Usage - man mv)

top - Display the processes similar to task manager. (Usage - top)

history - Displays all previously entered commands (Usage - history)













Custom single threaded java server

 package com.diffengine.csv; import java.io.*; import java.net.*; import java.util.Date; public class Server { public static void main(Str...