<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Let's go inside

    this blog is deprecated as a result of laziness.
    posts - 59, comments - 2, trackbacks - 0, articles - 0

    TrailBlazer第7天--MDB

    Posted on 2006-07-27 14:24 Earth 閱讀(224) 評論(0)  編輯  收藏 所屬分類: JavaEE5/EJB3

    The JMS clients send messages to message queues managed by the server (e.g., an email inbox can be a message queue). The message queues are monitored by a special kind of EJBs --Message Driven Beans (MDBs). The MDB processes the incoming messages and perform the services requested by the message. The MDBs are the end-point for JMS service request messages.
    JMS客戶端向消息隊列(比如收件箱)發送消息。
    消息隊列(收件箱)由MDB監視,MDB處理進來的消息并提供消息所需要的服務

    In this trail, the investment calculator application is refactored to use a Message Driven Bean. When you click on the "Calculate" button on the web form, the JSP page (calculator.jsp) sends a message containing the calculation parameters to a message queue. It then forwards to another JSP page (check.jsp) to periodically check whether the calculation result becomes available.
    當你點擊頁面中的Calculate按鈕時,JSP會把含有計算所需參數的信息發送到一個消息隊列,然后頁面跳轉到check.jsp, check.jsp不斷刷新自己以定期檢查計算結果是否可用。

    The message queue is monitored by a MDB, which retrieves the incoming message, parses its contents, and performs the calculation. After the calculation is done, the MDB saves the result to an application-wide shared cache. The result is then picked up and displayed by the result-monitoring JSP page (i.e., check.jsp).
    該消息隊列由一個MDB監控,當它檢索到一條消息后,解析消息內容,然后進行計算,然后把計算 結果放在application中。最后這個結果被check.jsp捕獲并顯示。

    1。監聽器 The Message Driven Beans

    @MessageDriven(activationConfig? =
    {
    ??@ActivationConfigProperty(propertyName
    = " destinationType " ,
    ????propertyValue
    = " javax.jms.Queue " ),
    ??@ActivationConfigProperty(propertyName
    = " destination " ,
    ????propertyValue
    = " queue/mdb " )
    })
    public ? class ?CalculatorBean? implements ?MessageListener?{

    ??
    public ? void ?onMessage?(Message?msg)?{
    ????
    try ?{
    ??????TextMessage?tmsg?
    = ?(TextMessage)?msg;
    ??????Timestamp?sent?
    =
    ??????????
    new ?Timestamp(tmsg.getLongProperty( " sent " ));
    ??????StringTokenizer?st?
    =
    ??????????
    new ?StringTokenizer(tmsg.getText(),? " , " );

    ??????
    int ?start? = ?Integer.parseInt(st.nextToken());
    ??????
    int ?end? = ?Integer.parseInt(st.nextToken());
    ??????
    double ?growthrate? = ?Double.parseDouble(st.nextToken());
    ??????
    double ?saving? = ?Double.parseDouble(st.nextToken());

    ??????
    double ?result? =
    ??????????calculate?(start,?end,?growthrate,?saving);
    ??????RecordManager.addRecord?(sent,?result);

    ????}?
    catch ?(Exception?e)?{
    ??????e.printStackTrace?();
    ????}
    ??}
    }

    MDB用@MessageDriven標注
    destinationType 表示所監聽的消息的類型
    destination 表示所監聽的消息隊列的名字(比如queue/mdb)
    如果這個隊列并不存在, JBoss會在deploy的時候自動創建一個,所以不需要XML配置文件!


    2。在客戶端的使用

    ? <% @?page? import = " trail.mdb.*,?javax.naming.*,?java.text.*,
    ??????????????????javax.jms. * ,
    ??????????????????java.sql.Timestamp
    " %>
    ?
    ?
    <%
    ???
    if ?( " send " .equals(request.getParameter?( " action " )))?{
    ?
    ?????QueueConnection?cnn?
    = ? null ;
    ?????QueueSender?sender?
    = ? null ;
    ?????QueueSession?sess?
    = ? null ;
    ?????Queue?queue?
    = ? null ;
    ?
    ?????
    try ?{
    ???????InitialContext?ctx?
    = ? new ?InitialContext();
    ???????queue?
    = ?(Queue)?ctx.lookup( " queue/mdb " );
    ???????QueueConnectionFactory?factory?
    =
    ???????????(QueueConnectionFactory)?ctx.lookup(
    " ConnectionFactory " );
    ???????cnn?
    = ?factory.createQueueConnection();
    ???????sess?
    = ?cnn.createQueueSession( false ,
    ???????????????????QueueSession.AUTO_ACKNOWLEDGE);
    ?
    ?????}?
    catch ?(Exception?e)?{
    ???????e.printStackTrace?();
    ?????}
    ?
    ?????TextMessage?msg?
    = ?sess.createTextMessage(
    ?????????request.getParameter?(
    " start " )? + ? " , " ? +
    ?????????request.getParameter?(
    " end " )? + ? " , " ? +
    ?????????request.getParameter?(
    " growthrate " )? + ? " , " ? +
    ?????????request.getParameter?(
    " saving " )
    ?????);
    ?????
    // ?The?sent?timestamp?acts?as?the?message's?ID
    ????? long ?sent? = ?System.currentTimeMillis();
    ?????msg.setLongProperty(
    " sent " ,?sent);
    ?
    ?????sender?
    = ?sess.createSender(queue);
    ?????sender.send(msg);
    ?????
    // ?sess.commit?();
    ?????sess.close?();
    ?
    %>

    To use the message driven bean, the client (i.e, JSP page calculator.jsp in this case) use the standard JMS API to obtain the target message queue to the MDB using the queue name (queue/mdb), and then send the message to the queue.

    to be continued

    主站蜘蛛池模板: 精品国产福利尤物免费| 亚洲av午夜电影在线观看| 国产99久久久国产精免费| 女性自慰aⅴ片高清免费| 久久久久久亚洲Av无码精品专口| 光棍天堂免费手机观看在线观看| 亚洲中文字幕视频国产| 日本高清不卡中文字幕免费| 男女啪啪永久免费观看网站| 亚洲成a人无码亚洲成av无码| 好爽…又高潮了毛片免费看| 亚洲国产欧洲综合997久久| 全免费一级午夜毛片| 亚洲一线产区二线产区精华| 无码日韩精品一区二区免费| 亚洲综合久久一本伊伊区| 夫妻免费无码V看片| 亚洲AV成人片无码网站| 亚洲国产精品一区二区第四页 | ww4545四虎永久免费地址| 亚洲最大黄色网站| 国产麻豆视频免费观看| 亚洲精品乱码久久久久蜜桃| 国产乱子伦精品免费女| 一本岛v免费不卡一二三区| 国产AV无码专区亚洲AWWW| 最近免费中文字幕MV在线视频3| 亚洲国产综合精品中文第一区| 国产2021精品视频免费播放| 日本亚洲色大成网站www久久| 国产一区在线观看免费| 免费无码又爽又刺激网站直播| 精品亚洲国产成AV人片传媒| 卡一卡二卡三在线入口免费| 免费国产污网站在线观看不要卡| 亚洲熟妇av一区二区三区 | 精品久久久久久久久免费影院| 337P日本欧洲亚洲大胆精品| 亚洲一区爱区精品无码| 日韩精品无码区免费专区| 免费又黄又爽又猛大片午夜 |