2011년 5월 23일 월요일

Starting Java Messaging System - 3

JMS PTP Test Program 작성
HelloWorldJmsSender.java
import javax.naming.*;
import javax.jms.*;
import java.util.Properties;
public class HelloWorldJmsSender{
public final static String JMS_FACTORY="QueueConnectionFactory";
public final static String QUEUE="ExampleQueue";
public static void main(String args[]) {
try {
QueueConnectionFactory queueConnectionFactory;
QueueConnection queueConnection;
QueueSession queueSession;
QueueSender queueSender;
Queue queue;
TextMessage msg;
// JNDI InitialContext 작성합니다.
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "jeus.jndi.JEUSContextFactory");
env.setProperty(Context.PROVIDER_URL, "localhost");
InitialContext ctx = new InitialContext(env);
// Connection Factory Queue Look up 합니다
queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
queue = (Queue) ctx.lookup(QUEUE);
// connection 작성
queueConnection = queueConnectionFactory.createQueueConnection();
// 세션을 작성
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// sender 작성
queueSender = queueSession.createSender(queue);
// 메세지를 작성
msg = queueSession.createTextMessage();
msg.setText("Hello World hurukku!!");
// 메세지의 배송을 스타트
queueConnection.start();
// 메세지를 송신
queueSender .send(msg);
// 접속을 close
queueSender.close();
queueSession.close();
queueConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

HelloWorldJmsReceiver.java
import javax.jms.*;
import javax.naming.*;
import java.util.Properties;
public class HelloWorldJmsReceiver {
public final static String JMS_FACTORY="QueueConnectionFactory";
public final static String QUEUE="ExampleQueue";
public static void main(String[] args) {
try {
QueueConnectionFactory queueConnectionFactory;
QueueConnection queueConnection;
QueueSession queueSession;
QueueReceiver queueReceiver;
Queue queue;
TextMessage msg;
// JNDI InitialContext 작성합니다
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "jeus.jndi.JEUSContextFactory");
env.setProperty(Context.PROVIDER_URL, "localhost");
InitialContext ctx = new InitialContext(env);
// Connection Factory Queue Look up 합니다
queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
queue = (Queue) ctx.lookup(QUEUE);
// connection 작성
queueConnection = queueConnectionFactory.createQueueConnection();
// 세션을 작성
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// 리시버를 작성
queueReceiver = queueSession.createReceiver(queue);
// 메세지의 배송을 스타트
queueConnection.start();
// 메세지의 수신
while (true) {
Message m = queueReceiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
msg = (TextMessage) m;
System.out.println(msg.getText());
} else {
break;
}
}
}
// 접속을 close
queueReceiver.close();
queueSession.close();
queueConnection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

Source Compile 및 실행
- Compile
“javac -classpath /home/craftlee/jeus/lib/system/jeus.jar *.java”
- Sender 실행
“java -classpath .:/home/craftlee/jeus/lib/system/jeus.jar:/home/craftlee/jeus/lib/system/jmxri.jar HelloWorldJmsSender”
jmsadmin에서 엔진모니터링
Destination Type : Queue
Name of Destination : ExampleQueue
JNDI name of Destination : ExampleQueue
Client information that is consuming this destination
-----------------------------------------------------
No client is consuming this destination.
number of messages remained in Queue : 1

- Receiver 실행
“java -classpath .:/home/craftlee/jeus/lib/system/jeus.jar:/home/craftlee/jeus/lib/system/jmxri.jar HelloWorldJmsReceiver”
Destination Type : Queue
Name of Destination : ExampleQueue
JNDI name of Destination : ExampleQueue
Client information that is consuming this destination
-----------------------------------------------------
client 0 : Address; 127.0.0.1, port; 34001
clientNumber; 0
number of messages remained in Queue : 0

댓글 없음:

댓글 쓰기

ETL 솔루션 환경

ETL 솔루션 환경 하둡은 대용량 데이터를 값싸고 빠르게 분석할 수 있는 길을 만들어줬다. 통계분석 엔진인 “R”역시 하둡 못지 않게 관심을 받고 있다. 빅데이터 역시 데이터라는 점을 볼때 분산처리와 분석 그 이전에 데이터 품질 등 데이...