隨筆-159  評論-114  文章-7  trackbacks-0
          啟動Weblogic服務器,由于JMS,需要一個消息中間件,Tuxedo。本文使用的是WebLogic 9.1,與8.1的有所不同。

          登錄

          logon.jpg

          創建JMS servers

          server.jpg


          設置完JMS服務器以后,要設置JMS的Modules,以便JMS客戶端和接受端能查找相應的JMSFactory和JMSdestination。

          module.jpg


          C:\bea\user_projects\domains\base_domain\config\jms

          會出現配置相關的配置文件

          建立兩個資源

          一個是ConnectionFactory,配置一個JNDI。

          另外一個是Queue-0,配置一個JNDI。

          resource.jpg

          import?javax.jms.*;
          import?java.util.Hashtable;
          import?javax.naming.*;
          import?java.io.*;

          public?class?QueueSend
          {
          ????
          ????
          public?static?void?main(String[]?args)?throws?Exception
          ????
          {
          ????????Hashtable?hash?
          =?new?Hashtable();
          ????????hash.put(Context.INITIAL_CONTEXT_FACTORY,
          "weblogic.jndi.WLInitialContextFactory");
          ????????hash.put(Context.PROVIDER_URL,
          "t3://localhost:7001");
          ????????
          ????????InitialContext?ic?
          =?new?InitialContext(hash);
          ????????
          ????????
          //找工廠
          ????????QueueConnectionFactory?factory?=?(QueueConnectionFactory)ic.lookup("jms/factory");
          ????????
          ????????System.out.println(factory.getClass());
          ????????
          ????????
          ????????
          //找文件夾,也就是目的地
          ????????Queue?queue?=?(Queue)ic.lookup("queue");
          ????????
          ????????System.out.println(queue.getClass());
          ????????
          ????????
          ????????
          //查API,接口有什么方法阿????????
          ????????QueueConnection?conn?=?(QueueConnection)factory.createQueueConnection();
          ????????
          ????????
          ????????
          //消息的接受者,是否給消息中間件回復,否則重復發送。第二參數使用自動確認
          ????????QueueSession?session?=?conn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
          ????????
          ????????
          //根據目的地,確定發送者
          ????????QueueSender?sender?=?session.createSender(queue);
          ????????
          ????????
          ????????
          //Message的創建要使用Session
          ????????
          ????????BufferedReader?buffer?
          =?new?BufferedReader(new?InputStreamReader(System.in));
          ????????
          ????????
          while(true)
          ????????
          {
          ????????????String?line?
          =?buffer.readLine();
          ????????????
          if(line.equals("quit"))
          ????????????
          {
          ????????????????TextMessage?message?
          =?session.createTextMessage("over");
          ????????????????sender.send(message);?????????
          ????????????????
          break;????????????????
          ????????????}

          ????????????TextMessage?message?
          =?session.createTextMessage(line);
          ????????????sender.send(message);?????????
          ????????}

          ????????
          ??????????????
          ????????
          ????}



          }


          察看一下Queue資源,就能看到自己發送的TextMessage。

          下回分解MDB。

          posted on 2006-03-25 21:34 北國狼人的BloG 閱讀(425) 評論(0)  編輯  收藏 所屬分類: 達內學習總結
          主站蜘蛛池模板: 汪清县| 佛坪县| 美姑县| 合山市| 滁州市| 墨竹工卡县| 瓦房店市| 东安县| 高陵县| 繁峙县| 衡阳市| 广安市| 皋兰县| 崇文区| 黄石市| 宿州市| 龙岩市| 通化县| 克山县| 江城| 同德县| 阳原县| 思茅市| 班戈县| 晋江市| 务川| 称多县| 信宜市| 康平县| 姚安县| 正蓝旗| 通江县| 淮南市| 新和县| 离岛区| 沭阳县| 宽甸| 藁城市| 金溪县| 泌阳县| 会宁县|