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

          登錄

          logon.jpg

          創(chuàng)建JMS servers

          server.jpg


          設(shè)置完JMS服務(wù)器以后,要設(shè)置JMS的Modules,以便JMS客戶端和接受端能查找相應(yīng)的JMSFactory和JMSdestination。

          module.jpg


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

          會出現(xiàn)配置相關(guān)的配置文件

          建立兩個資源

          一個是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();
          ????????
          ????????
          ????????
          //消息的接受者,是否給消息中間件回復(fù),否則重復(fù)發(fā)送。第二參數(shù)使用自動確認
          ????????QueueSession?session?=?conn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
          ????????
          ????????
          //根據(jù)目的地,確定發(fā)送者
          ????????QueueSender?sender?=?session.createSender(queue);
          ????????
          ????????
          ????????
          //Message的創(chuàng)建要使用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資源,就能看到自己發(fā)送的TextMessage。

          下回分解MDB。

          posted on 2006-03-25 21:34 北國狼人的BloG 閱讀(417) 評論(0)  編輯  收藏 所屬分類: 達內(nèi)學(xué)習(xí)總結(jié)
          主站蜘蛛池模板: 涟源市| 客服| 长顺县| 新宾| 新余市| 财经| 金寨县| 乐平市| 大厂| 安宁市| 时尚| 平利县| 德江县| 平远县| 虹口区| 桐乡市| 云南省| 怀远县| 河东区| 临桂县| 安平县| 昂仁县| 重庆市| 鄂尔多斯市| 都江堰市| 仪征市| 修文县| 囊谦县| 南汇区| 扎赉特旗| 万载县| 大足县| 桂林市| 龙胜| 健康| 和静县| 顺义区| 盐池县| 龙里县| 茶陵县| 原阳县|