2017-11-16 10 views
0

Tibco EMS 큐에 메시지를 게시 할 JMS 응용 프로그램을 작성중인 메시지를 게시하려고합니다. 하나는 정상 로깅 용이고 다른 하나는 예외 로깅 용 대기열입니다. 이제 JMS에서 두 개의 다른 대기열에 메시지를 보내는 방법. 그것은 매우 중요하므로 아무도 나를 도울 수 있습니까?JMS 전송 메시지

+0

구현하기에 문제가 어디 있는지 알 수 없습니까? – Losusovic

+0

일반적으로 우리는 한 큐로 메시지를 보냅니다. 그러나 여기에서는 두 가지 종류의 메시지를 두 개의 서로 다른 대기열에 보내야합니다. 로깅을위한 하나의 큐와 오류를위한 큐. – user2713075

답변

0

대기열로 메시지를 보내는 매우 기본적인 JMS API 코드는 아래와 같습니다. 사용자 환경에 따라 연결 팩토리와 큐 이름을 조정해야합니다. 또한 초기 컨텍스트 설정을 조정해야합니다.

void sendMessage() { 
    Connection con = null; 
    try { 

     // Get the initial context 
     Hashtable<String, String> hTable = new Hashtable<String, String>(); 
     hTable.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); 
     hTable.put(Context.PROVIDER_URL, "t3://localhost:7001"); 
     Context ctx = new InitialContext(hTable); 

     // Create ConnectionFactory 
     ConnectionFactory cf = (ConnectionFactory) ctx.lookup("JMS-JNDI-ConFactory"); 

     // Create connection 
     con = cf.createConnection(); 

     // Create Non transacted Session with auto ack 
     Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); 

     // Create the destination 
     Queue queue = (Queue) ctx.lookup("JMS-JNDI-Queue"); 

     // Create MessageProducer for the destination 
     MessageProducer producer = session.createProducer(queue); 

     // Create empty Message with header and properties only 
     TextMessage message = session.createTextMessage(); 

     // set the message body 
     message.setText("Message-1"); 

     // Send the message 
     producer.send(message); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } finally { 
     if (con != null) { 
      try { 
       con.close(); 
      } catch (JMSException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 
+0

고마워.하지만 두 가지 종류의 메시지를 두 개의 서로 다른 대기열에 보내야합니다. 로깅을위한 하나의 큐와 오류를위한 큐. – user2713075

+0

이것은 메시지를 보내는 방법을 자세히 설명하는 샘플입니다. 코드를 재사용하여 모든 유형의 메시지를 다른 대기열로 보낼 수 있습니다. –