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

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

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

    隨筆-88  評(píng)論-77  文章-48  trackbacks-0

    package com.zte.jms;

    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.Queue;
    import javax.jms.QueueConnection;
    import javax.jms.QueueConnectionFactory;
    import javax.jms.QueueReceiver;
    import javax.jms.QueueSender;
    import javax.jms.QueueSession;
    import javax.jms.TextMessage;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;

    import EDU.oswego.cs.dl.util.concurrent.CountDown;

    /**
    ?* A complete JMS client example program that sends N TextMessages to a Queue B
    ?* and asynchronously receives the messages as modified by TextMDB from Queue A.
    ?*
    ?* @author Scott.Stark@jboss.org
    ?* @version $Revision: 1.9 $
    ?*/
    public class SendRecvClient {
    ?static final int N = 10;

    ?static CountDown done = new CountDown(N);

    ?QueueConnection conn;

    ?QueueSession session;

    ?Queue queA;

    ?Queue queB;

    ?public static class ExListener implements MessageListener {
    ??public void onMessage(Message msg) {
    ???done.release();
    ???TextMessage tm = (TextMessage) msg;
    ???try {
    ????System.out.println("onMessage, recv text=" + tm.getText());
    ???} catch (Throwable t) {
    ????t.printStackTrace();
    ???}
    ??}
    ?}

    ?public void setupPTP() throws JMSException, NamingException {
    ??InitialContext iniCtx = InitContext.getInitContext();
    ??Object tmp = iniCtx.lookup("ConnectionFactory");
    ??QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
    ??conn = qcf.createQueueConnection();
    ??queA = (Queue) iniCtx.lookup("queue/A");
    ??queB = (Queue) iniCtx.lookup("queue/B");
    ??session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    ??conn.start();
    ?}

    ?public void sendRecvAsync(String textBase) throws JMSException,
    ???NamingException, InterruptedException {
    ??System.out.println("Begin sendRecvAsync");

    ??// Setup the PTP connection, session
    ??setupPTP();

    ??// Set the async listener for queA
    ??QueueReceiver recv = session.createReceiver(queA);
    ??recv.setMessageListener(new ExListener());

    ??// Send a few text msgs to queB
    ??QueueSender send = session.createSender(queB);

    ??for (int m = 0; m < 10; m++) {
    ???TextMessage tm = session.createTextMessage(textBase + "#" + m);
    ???tm.setJMSReplyTo(queA);
    ???send.send(tm);
    ???System.out.println("sendRecvAsync, sent text=" + tm.getText());
    ??}
    ??System.out.println("End sendRecvAsync");
    ?}

    ?public void stop() throws JMSException {
    ??conn.stop();
    ??session.close();
    ??conn.close();
    ?}

    ?public static void main(String args[]) throws Exception {
    ??System.out.println("Begin SendRecvClient,now="
    ????+ System.currentTimeMillis());
    ??SendRecvClient client = new SendRecvClient();
    ??client.sendRecvAsync("A text msg");
    ??client.done.acquire();
    ??client.stop();
    ??System.exit(0);
    ??System.out.println("End SendRecvClient");
    ?}

    }

    posted on 2006-04-24 19:16 崛起的程序員 閱讀(332) 評(píng)論(0)  編輯  收藏 所屬分類: java
    主站蜘蛛池模板: 久久精品人成免费| 亚洲AV第一页国产精品| 日韩精品极品视频在线观看免费| 亚洲AV无码专区在线电影成人 | 亚洲精品国产成人| 亚洲人成电影网站国产精品| 女人18毛片特级一级免费视频 | 亚洲第一成人影院| 好爽…又高潮了免费毛片| 无码人妻一区二区三区免费看| 在线免费视频你懂的| 免费毛片毛片网址| 久久亚洲精品11p| 亚洲毛片无码专区亚洲乱| 亚洲国产另类久久久精品黑人| 免费a级毛片永久免费| 日韩a在线观看免费观看| 我想看一级毛片免费的| 毛片a级毛片免费观看免下载| 久久国产乱子伦精品免费不卡| 美女被爆羞羞网站免费| 久久亚洲中文无码咪咪爱| 中文日韩亚洲欧美制服| 亚洲综合色区中文字幕| 亚洲国产精品久久丫| 亚洲视频一区在线播放| 亚洲成a人片77777老司机| 亚洲成AV人片在线观看| 999国内精品永久免费观看| 亚洲av乱码一区二区三区| 日本中文一区二区三区亚洲| 四虎永久在线精品免费观看地址| 日韩免费一区二区三区在线播放| 91免费在线播放| 亚洲免费视频播放| 国产精品免费观看久久| 成年免费大片黄在线观看岛国| 永久免费AV无码国产网站| 野花高清在线电影观看免费视频 | 在线播放亚洲第一字幕| 亚洲国产中文字幕在线观看|