<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
    主站蜘蛛池模板: 亚洲精品自在在线观看| 婷婷亚洲久悠悠色悠在线播放| 色欲aⅴ亚洲情无码AV蜜桃| 免费黄网在线观看| 美女视频黄.免费网址| 亚洲动漫精品无码av天堂| 思思re热免费精品视频66| 偷自拍亚洲视频在线观看99| 亚洲AV无码一区东京热久久| 好先生在线观看免费播放 | 亚洲乱码精品久久久久..| 日本xxxx色视频在线观看免费| 亚洲国产aⅴ成人精品无吗| 亚洲电影一区二区| 国产乱子影视频上线免费观看| 91精品免费不卡在线观看| 美女黄频a美女大全免费皮| 亚洲熟妇无码爱v在线观看| 中文亚洲AV片不卡在线观看| 国产a不卡片精品免费观看| 日本免费xxxx| 在线成人爽a毛片免费软件| 国产国产人免费人成成免视频 | 亚洲精品夜夜夜妓女网| 国产精品自在自线免费观看| 成年人视频免费在线观看| 国产又黄又爽胸又大免费视频| 西西人体大胆免费视频| 亚洲精品国产suv一区88| 亚洲午夜久久久精品电影院| 久久精品国产精品亚洲精品| 免费午夜爽爽爽WWW视频十八禁 | 精品亚洲国产成人| 亚洲国产精品张柏芝在线观看| 亚洲男人天堂av| 亚洲色欲www综合网| 亚洲美女视频网站| 亚洲日本香蕉视频观看视频| 亚洲日本中文字幕区| 中文字幕亚洲精品| 亚洲精品在线播放|