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

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

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

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

    1,項目中所引的包

     

    2,發送和接受消息的代碼,每個都是一個Junit函數

    package test;

    import javax.jms.Destination;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.Session;
    import javax.jms.TextMessage;

    import junit.framework.TestCase;

    import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;
    import org.springframework.jms.core.JmsTemplate;
    import org.springframework.jms.core.MessageCreator;

    public class ActivemqTest extends TestCase {
     @Test
     public void testJmsTemplateSend() {      

      ApplicationContext ctx = new FileSystemXmlApplicationContext(
        "WebRoot/WEB-INF/applicationContext.xml");
      JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
      Destination destination = (Destination) ctx.getBean("destination");

      template.send(destination, new MessageCreator() {
       public Message createMessage(Session session) throws JMSException {
        return session.createTextMessage("發送消息:Hello ActiveMQ Text Message!");
       }
      });
      System.out.println("成功發送了一條JMS消息");
     }

     @Test
     public void testJmsTemplateReceive() throws JMSException {
      ApplicationContext ctx = new FileSystemXmlApplicationContext(
        "WebRoot/WEB-INF/applicationContext.xml");
      JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
      Destination destination = (Destination) ctx.getBean("destination");
      while (true) {
       TextMessage txtmsg = (TextMessage) template.receive(destination);
       if (null != txtmsg)
        System.out.println("收到消息內容為: " + txtmsg.getText());
       else
        break;
      }
     }

     public static void main(String[] args) throws Exception{
      new ActivemqTest().testJmsTemplateSend();
      
      new ActivemqTest().testJmsTemplateReceive();
     }
    }

     

    3,applicationContext.xml文件內容

    <?xml version="1.0" encoding="UTF-8"?>  
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
           xmlns:context="http://www.springframework.org/schema/context
           xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">  
     
        <!-- 配置JMS連接工廠 -->  
        <bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">  
            <property name="brokerURL" value="tcp://localhost:61616"/>  
        </bean>  
     
        <!-- 配置JMS模版 -->  
        <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">  
            <property name="connectionFactory" ref="connectionFactory"/>  
        </bean>  
     
        <!-- 發送消息的目的地(一個隊列) -->  
        <bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">  
            <!-- Set the Queue Name -->  
            <constructor-arg index="0" value="HelloWorldQueue"/>  
        </bean>  
    </beans>




    http://blog.csdn.net/hnzhangshilong/article/details/6629780

    posted on 2012-08-25 21:34 abin 閱讀(1058) 評論(0)  編輯  收藏 所屬分類: ActiveMQ
    主站蜘蛛池模板: 亚洲无mate20pro麻豆| 国内精品99亚洲免费高清| 亚洲高清无码综合性爱视频| 久久WWW免费人成—看片| 亚洲精品成人图区| 国产女高清在线看免费观看| 99久久国产精品免费一区二区| 国产亚洲国产bv网站在线| 中文字幕在亚洲第一在线| 免费看黄视频网站| 九九99热免费最新版| 亚洲国产精品成人AV在线 | 亚洲午夜国产精品无码老牛影视 | 国产精品久久久久免费a∨| 深夜久久AAAAA级毛片免费看| 亚洲资源在线观看| 亚洲情a成黄在线观看| 免费无码又黄又爽又刺激| 久久99毛片免费观看不卡| 亚洲s码欧洲m码吹潮| 久久亚洲精精品中文字幕| 亚洲国产婷婷综合在线精品| 成人女人A级毛片免费软件| 伊人免费在线观看| 日本免费精品一区二区三区| 亚洲a级在线观看| 久久久亚洲精品无码| 亚洲精品视频在线看| 麻豆国产精品入口免费观看| 麻豆成人久久精品二区三区免费| 一区二区三区免费视频观看| 亚洲最大的成人网| 亚洲国产成人精品无码区在线网站| 亚洲最大AV网站在线观看| 午夜国产羞羞视频免费网站| 免费无码肉片在线观看| 亚洲免费在线视频观看| 久久综合九色综合97免费下载| 成人福利在线观看免费视频| 精品亚洲国产成人av| 亚洲色成人四虎在线观看|