?? ptpreceiver.java
字號:
import javax.naming.*;
import javax.jms.*;
public class PTPReceiver {
private Connection connection;
private Session session;
private MessageConsumer consumer;
public static void main(String[] args) {
PTPReceiver receiver = null;
try {
receiver = new PTPReceiver();
String textMsg;
textMsg = receiver.consumeMessage();
System.out.println ("Received: " + textMsg);
}
catch(Exception ex) {
System.err.println("Exception in PTPReceiver: " + ex);
}
finally {
try {receiver.close();} catch(Exception ex){}
}
}
public PTPReceiver() throws JMSException, NamingException {
Context context = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup("jms/QueueConnectionFactory");
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = (Destination)context.lookup("jms/firstQueue");
consumer = session.createConsumer(destination);
connection.start();
}
public String consumeMessage () throws JMSException {
String text = null;
Message msgBody = consumer.receive();
if (msgBody instanceof TextMessage) {
text = ((TextMessage) msgBody).getText();
}
else {
text = msgBody.toString();
}
return text;
}
public void close() throws JMSException {
connection.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -