?? bbpublisher.java
字號:
import javax.naming.*;
import javax.jms.*;
public class BBPublisher {
private Connection connection;
private Session session;
private MessageProducer producer;
public static void main(String[] args) {
BBPublisher publisher = null;
try {
publisher = new BBPublisher("jms/TopicConnectionFactory","jms/bulletinBoard");
System.out.println ("Publisher is up and running");
for (int i = 0; i < 10; i++) {
String bulletin = "Bulletin Board Message number: " + i;
System.out.println (bulletin);
publisher.sendMessage(bulletin);
}
}
catch(Exception ex) {
System.err.println("Exception in BulletinBoardPublisher: " + ex);
}
finally {
try {publisher.close();} catch(Exception ex){}
}
}
public BBPublisher(String JNDIconnectionFactory, String JNDItopic) throws JMSException, NamingException {
Context context = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory)context.lookup(JNDIconnectionFactory);
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination bulletinBoard = (Destination)context.lookup(JNDItopic);
producer = session.createProducer(bulletinBoard);
}
public void sendMessage(String msg) throws JMSException {
TextMessage message = session.createTextMessage();
message.setText(msg);
producer.send(message);
}
public void close() throws JMSException {
connection.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -