달력

072018  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  
  •  
  •  
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
Posted by Tornado tornado