0
안녕하세요 아래 클래스를 작성하여 jibco jms 대기열에서 메시지를 읽습니다. 다른 클래스에서이 클래스의 인스턴스를 만들고 getMessage()를 흔들어 봅니다. 대기열에 메시지를 놓았습니다. getMessage() 메서드를 호출 할 때 내 응용 프로그램이 멈추었습니다 ... 어떤 생각입니까? 또는 내가 아래 수업에 추가 할 수있는 개선? 이 큐에서 메시지를 수신 할 때까지TIBCO JMS 대기열 메시지 수신자가 멈춤
public class EMSReceiver {
private QueueConnection connection;
private QueueReceiver queueReceiver;
private Queue queue;
private TextMessage message;
public EMSReceiver(String initialContextFactory, String userName, String password, String serverUrl, String confact, String q){
try {
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.PROVIDER_URL, serverUrl);
InitialContext jndi = new InitialContext(env);
QueueConnectionFactory connectionFactory = (QueueConnectionFactory) jndi.lookup(confact);
QueueConnection connection = connectionFactory.createQueueConnection(userName, password);
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
this.queue = (Queue) jndi.lookup(q);
this.queueReceiver = session.createReceiver(queue);
connection.start();
}
catch (JMSException e) {
e.printStackTrace();
System.exit(0);
} catch (NamingException e) {
e.printStackTrace();
}
}
public String getMessage() throws JMSException{
try {
this.message = (TextMessage) queueReceiver.receive();
} catch (JMSException e) {
System.out.println("Could not retrieve the message.");
e.printStackTrace();
}
return message.getText();
}
메시지를 큐에 넣는 코드를 공유 할 수 있습니까? – Priyesh
괜찮습니다. 에 관계없이 내가 메시지를 배치하는 방법 ... 위의 코드 중 하나를 문자열 또는 NULL 오른쪽으로 인쇄해야합니다? 걸러서는 안됩니다 ... – Achilles
대기열에서 메시지를 수신 할 때까지 기다립니다. 기다리지 않으려면 receiveNoWait()을 사용하거나 receive (long timeout)을 사용하십시오. 이 문서는 https://javaee-spec.java.net/nonav/javadocs/javax/jms/QueueReceiver.html에서 볼 수 있습니다. – Priyesh