QueueFiller.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package bible.webservices.message.producer;
- import javax.naming.*;
- import javax.jms.*;
- import java.util.*;
- /**
- * Class QueueFiller
- *
- *
- * @author
- * @version %I%, %G%
- */
- public class QueueFiller {
- /**
- * Constructor QueueFiller
- *
- *
- */
- public QueueFiller() {}
- /**
- * Method main
- *
- *
- * @param args
- *
- */
- public static void main(String[] args) {
- Context ctx = null;
- QueueConnectionFactory qConnectionFactory = null;
- QueueConnection qConnection = null;
- QueueSession qSession = null;
- QueueSender qSender = null;
- try {
- Properties props = new Properties();
- props.put(Context.INITIAL_CONTEXT_FACTORY,
- "weblogic.jndi.WLInitialContextFactory");
- props.put(Context.PROVIDER_URL, "t3://localhost:7001");
- ctx = new InitialContext(props);
- qConnectionFactory =
- (QueueConnectionFactory) ctx
- .lookup("bible/ws/message/ReceiveConnectionFactory");
- qConnection = qConnectionFactory.createQueueConnection();
- qSession = qConnection.createQueueSession(false,
- javax.jms.QueueSession.AUTO_ACKNOWLEDGE);
- Queue q = (Queue) ctx.lookup("ReceiveQueue");
- qSender = qSession.createSender(q);
- System.out.println("Sending messages to the client...");
- ObjectMessage message = qSession.createObjectMessage();
- for (int i = 0; i < 10; i++) {
- message.clearBody();
- message.setObject("Message #" + i + " data to the client");
- System.out.println("Sending message #" + i);
- qSender.send(message);
- }
- message.clearBody();
- message.setObject("Stop");
- System.out.println("Sending message " + message.getObject());
- qSender.send(message);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- qSender.close();
- qSession.close();
- qConnection.close();
- } catch (Exception ex) {}
- }
- }
- }
- /*--- Formatted in Bible Style on Thu, Sep 6, '01 ---*/
- /*------ Formatted by Jindent 3.24 Gold 1.02 --- http://www.jindent.de ------*/