当前位置: 首页>>代码示例>>Java>>正文


Java QueueSession.createMessage方法代码示例

本文整理汇总了Java中javax.jms.QueueSession.createMessage方法的典型用法代码示例。如果您正苦于以下问题:Java QueueSession.createMessage方法的具体用法?Java QueueSession.createMessage怎么用?Java QueueSession.createMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.QueueSession的用法示例。


在下文中一共展示了QueueSession.createMessage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTempQueueDelete

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test
public void testTempQueueDelete() throws Exception {
   connection.start();
   QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   TemporaryQueue tempQueue = queueSession.createTemporaryQueue();

   ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
   try {
      QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueSender queueSender = newQueueSession.createSender(tempQueue);

      Message msg = queueSession.createMessage();
      queueSender.send(msg);

      try {
         QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
         fail("should have gotten exception but got consumer: " + consumer);
      } catch (JMSException ex) {
         //correct
      }

      connection.close();

      try {
         Message newMsg = newQueueSession.createMessage();
         queueSender.send(newMsg);
      } catch (JMSException e) {
         //ok
      }

   } finally {
      newConn.close();
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:36,代码来源:SimpleOpenWireTest.java

示例2: getMessageCount

import javax.jms.QueueSession; //导入方法依赖的package包/类
private static int getMessageCount(final Connection connection) throws Exception {
   QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");

   QueueRequestor requestor = new QueueRequestor(session, managementQueue);

   connection.start();

   Message m = session.createMessage();

   JMSManagementHelper.putAttribute(m, ResourceNames.QUEUE + "exampleQueue", "messageCount");

   Message response = requestor.request(m);

   int messageCount = (Integer) JMSManagementHelper.getResult(response, Integer.class);

   return messageCount;
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:PreacknowledgeExample.java

示例3: testSendEmptyMessages

import javax.jms.QueueSession; //导入方法依赖的package包/类
@Test
public void testSendEmptyMessages() throws Exception {
   Queue dest = new ActiveMQQueue(queueName);

   QueueSession defaultQueueSession =  connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   QueueSender defaultSender = defaultQueueSession.createSender(dest);
   defaultSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
   connection.start();

   Message msg = defaultQueueSession.createMessage();
   msg.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(msg);

   QueueReceiver queueReceiver = defaultQueueSession.createReceiver(dest);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //bytes
   BytesMessage bytesMessage = defaultQueueSession.createBytesMessage();
   bytesMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(bytesMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //map
   MapMessage mapMessage = defaultQueueSession.createMapMessage();
   mapMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(mapMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //object
   ObjectMessage objMessage = defaultQueueSession.createObjectMessage();
   objMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(objMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //stream
   StreamMessage streamMessage = defaultQueueSession.createStreamMessage();
   streamMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(streamMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //text
   TextMessage textMessage = defaultQueueSession.createTextMessage();
   textMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(textMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:47,代码来源:SimpleOpenWireTest.java


注:本文中的javax.jms.QueueSession.createMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。