2011-08-26 2 views
0

GlassFish (2.1) 서버에서 JMS 메시지를 원격으로 수신하려고합니다. 나는 여기에 지침을 따라 갔다 : http://www.tidytutorials.com/2009/06/jms-example-using-glassfish-and-remote.html 그리고 여기에 : http://www.novell.com/documentation/extend52/Docs/help/MP/jms/tutorial/pointToPoint-1.htm 하지만 작동하지 않는 것 같다.원격 GlassFish 서버에서 JMS 메시지 받기

테스트를 위해 QueueConnectionFactory sampleFactory 및 Queue sampleQueue를 만들었습니다.

나는 메시지를 보내려면 다음 코드를 사용

HashMap<String,List<String>> values = getValues(); 
InitialContext context = new InitialContext(); 

QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup("sampleFactory"); 
Queue queue = (Queue) context.lookup("sampleQueue"); 

queueConnection = factory.createQueueConnection(); 
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 
queueSender = queueSession.createSender(queue); 
ObjectMessage message = queueSession.createObjectMessage(); 
message.setObject(values); 

queueSender.send(message); 

내 클라이언트는 다음과 같은 코드를 사용 :

class JMSListener implements Runnable, MessageListener { 

.... 
public void run() { 
    try { 
     System.out.println("Started JMS Listener"); 

     Properties props = new Properties(); 
     props.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.appserv.naming.S1ASCtxFactory"); 
     props.put(Context.PROVIDER_URL,"iiop://192.168.38.164:3700"); 

     Context ctx = new InitialContext(props); 


     Queue queue = (Queue) ctx.lookup("sampleQueue"); 

     QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup("sampleFactory"); 

     QueueConnection queueConnection = connectionFactory.createQueueConnection(); 

     QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 
     QueueReceiver queueReceiver = queueSession.createReceiver(queue); 
     queueConnection.start(); 

     queueReceiver.setMessageListener(new JMSListener()); 

     while (true) { 
      if(!Thread.currentThread().equals(runner)) break; 
      try { 
       Thread.sleep(10000); 
      } catch (InterruptedException ex) { 
       Logger.getLogger(JMSListenerRemote.class.getName()).log(Level.SEVERE, null, ex); 
      } 
     } 
     System.out.println("CLOSING!"); 
     // Don't leak 
     queueConnection.close(); 
    } catch (NamingException ex) { 
     Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex); 
    } catch (JMSException ex) { 
     Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 

public void onMessage(Message message) { 
    System.out.println("Got a message!"); 
    try { 
     ObjectMessage obj = (ObjectMessage) message; 

     HashMap<String, List<String>> values = (HashMap<String, List<String>>) obj.getObject(); 
     for (Entry<String, List<String>> entry : values.entrySet()) { 
      System.out.println("Got key: "+entry.getKey()); 
     } 
    } catch (JMSException ex) { 
     Logger.getLogger(Listener.class.getName()).log(Level.SEVERE, null, ex); 
    } 
} 
} 

내가 몇 가지 기록을 추가하기 때문에 정확하게 연결할 수 것을 대기열과 공장이 모두 괜찮은지 확인하고 있습니다. 큐 또는 팩토리의 이름을 변경하면 오류가 발생하므로 예상대로 작동합니다.

실제로는 메시지를 수신하지만 작동하지 않는 것은 무엇입니까? 그들은 좋아 보인다. 그러나 그들은 결코 클라이언트에 도착하지 않는다.

무엇이 잘못 되었을지에 대한 아이디어가 있습니까?

감사합니다.

편집 : 아, GlassFish에 내장 된 JMS 공급자를 사용하고 있습니다.

+1

업데이트 : GlassFish와 동일한 시스템에서 클라이언트를 실행하고 iiop : //127.0.0.1 : 3700을 사용하면 작동합니다. 따라서 코드가 올바르지 만 어떤 작업을해야할지 모르겠습니다. 원격으로 작동 시키려면 – Petter

+0

실제로 웹 응용 프로그램으로 GlassFish에서 실행 중일 때만 작동합니다. 독립 실행 형 응용 프로그램으로 실행하면 동일한 컴퓨터에서도 작동하지 않습니다. – Petter

+0

IMQAdmin 도구를 사용하면 대기열에 실제로 메시지가 수신되었는지 확인할 수 있습니까? \ glassfish \ imq \ bin \ imqadmin.exe – Preston

답변

0

좋습니다, 이것에 대한 해결책을 찾았습니다. 실제로 이상적은 아니지만 작동합니다.

이 작업을 수행하려면 원격 시스템에서 GlassFish를 실행해야합니다. 이 경우 JMS 설정 (구성 -> Java Message Service)을 일부 변경해야했으며, 유형을 REMOTE로 설정해야했으며 다른 GlassFish 인스턴스의 IP 주소를 사용하도록 default_JMS_Host를 변경해야했습니다.

위의 코드를 웹 응용 프로그램으로 실행하면 메시지를받는 것이 예상대로 작동합니다. 독립 실행 형 응용 프로그램으로 실행하고 싶다면 어떻게 작동시키는 지 아직 모릅니다.

+0

아마'appclient'를 사용하여 클라이언트 컴퓨터에서 실행하고 싶을 것입니다. 그것은 JAR 파일을로드하고, 삽입하고, 다른 컴퓨터에 메시지를 보냅니다. – Thufir

0

메시지 수신기를 먼저 설정하면 어떻게됩니까? 이 하나의 주제이며,

queueReceiver.setMessageListener(this); 
queueConnection.start(); 

오라일리가 온라인으로 몇 가지 예를 가지고 (또한, 당신은 동일한 인스턴스를 사용할 수 있습니다)하지만, 하드 비교하는 것을 안/적응 :

http://onjava.com/pub/a/onjava/excerpt/jms_ch2/index.html?page=2

+0

주문을 변경하거나 "this"를 사용하는 데 도움이되지 않았지만 예제를 살펴 보겠습니다. 감사합니다! – Petter

관련 문제