當前位置: 首頁>>代碼示例>>Java>>正文


Java MapMessage.getString方法代碼示例

本文整理匯總了Java中javax.jms.MapMessage.getString方法的典型用法代碼示例。如果您正苦於以下問題:Java MapMessage.getString方法的具體用法?Java MapMessage.getString怎麽用?Java MapMessage.getString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jms.MapMessage的用法示例。


在下文中一共展示了MapMessage.getString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractString

import javax.jms.MapMessage; //導入方法依賴的package包/類
@Override
protected String extractString(JMSBindingData binding) throws Exception {
    Message content = binding.getMessage();
    if (content instanceof TextMessage) {
        return TextMessage.class.cast(content).getText();
    
    } else if (content instanceof BytesMessage) {
        BytesMessage sourceBytes = BytesMessage.class.cast(content);
        if (sourceBytes.getBodyLength() > Integer.MAX_VALUE) {
            throw JCAMessages.MESSAGES.theSizeOfMessageContentExceedsBytesThatIsNotSupportedByThisOperationSelector("" + Integer.MAX_VALUE);
        }
        byte[] bytearr = new byte[(int)sourceBytes.getBodyLength()];
        sourceBytes.readBytes(bytearr);
        return new String(bytearr);

    } else if (content instanceof ObjectMessage) {
        ObjectMessage sourceObj = ObjectMessage.class.cast(content);
        return String.class.cast(sourceObj.getObject());

    } else if (content instanceof MapMessage) {
        MapMessage sourceMap = MapMessage.class.cast(content);
        return sourceMap.getString(KEY);
    } else {
        return content.getStringProperty(KEY);
    }
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:27,代碼來源:JMSOperationSelector.java

示例2: getDlqMessage

import javax.jms.MapMessage; //導入方法依賴的package包/類
/**
 * Waits a couple of seconds for a message to appear on the Dead Letter Queue for the provided endpointId - useful
 * if the test is designed to fail a stage (i.e. that a stage raises some {@link RuntimeException}, or the special
 * {@link MatsRefuseMessageException}).
 *
 * @param endpointId
 *            the endpoint which is expected to generate a DLQ message.
 * @return the {@link MatsTrace} of the DLQ'ed message.
 */
public MatsTrace getDlqMessage(String endpointId) {
    FactoryConfig factoryConfig = getMatsFactory().getFactoryConfig();
    String dlqQueueName = "DLQ." + factoryConfig.getMatsDestinationPrefix() + endpointId;
    try {
        Connection jmsConnection = _amqClient.createConnection();
        try {
            Session jmsSession = jmsConnection.createSession(true, Session.SESSION_TRANSACTED);
            Queue dlqQueue = jmsSession.createQueue(dlqQueueName);
            MessageConsumer dlqConsumer = jmsSession.createConsumer(dlqQueue);
            jmsConnection.start();

            final int maxWaitMillis = 5000;
            log.info("Listening for message on queue [" + dlqQueueName + "].");
            Message msg = dlqConsumer.receive(maxWaitMillis);

            if (msg == null) {
                throw new AssertionError("Did not get a message on the queue [" + dlqQueueName + "] within "
                        + maxWaitMillis + "ms.");
            }

            MapMessage matsMM = (MapMessage) msg;
            String matsTraceString = matsMM.getString(factoryConfig.getMatsTraceKey());
            log.info("!! Got a DLQ Message! MatsTraceString:\n" + matsTraceString);
            jmsSession.commit();
            jmsConnection.close(); // Closes session and consumer
            return _matsStringSerializer.deserializeMatsTrace(matsTraceString);
        }
        finally {
            jmsConnection.close();
        }
    }
    catch (JMSException e) {
        throw new IllegalStateException("Got a JMSException when trying to receive Mats message on [" + dlqQueueName
                + "].", e);
    }
}
 
開發者ID:stolsvik,項目名稱:mats,代碼行數:46,代碼來源:Rule_Mats.java

示例3: receiveMapMessage

import javax.jms.MapMessage; //導入方法依賴的package包/類
private void receiveMapMessage(boolean useCore) throws Exception {
   MapMessage mapMessage = (MapMessage) receiveMessage(useCore);

   boolean booleanVal = mapMessage.getBoolean("boolean-type");
   assertTrue(booleanVal);
   byte byteVal = mapMessage.getByte("byte-type");
   assertEquals((byte) 10, byteVal);
   byte[] bytesVal = mapMessage.getBytes("bytes-type");
   byte[] originVal = TEXT.getBytes();
   assertEquals(originVal.length, bytesVal.length);
   for (int i = 0; i < bytesVal.length; i++) {
      assertTrue(bytesVal[i] == originVal[i]);
   }
   char charVal = mapMessage.getChar("char-type");
   assertEquals('A', charVal);
   double doubleVal = mapMessage.getDouble("double-type");
   assertEquals(55.3D, doubleVal, 0.1D);
   float floatVal = mapMessage.getFloat("float-type");
   assertEquals(79.1F, floatVal, 0.1F);
   int intVal = mapMessage.getInt("int-type");
   assertEquals(37, intVal);
   long longVal = mapMessage.getLong("long-type");
   assertEquals(56652L, longVal);
   Object objectVal = mapMessage.getObject("object-type");
   Object origVal = new String("VVVV");
   assertTrue(objectVal.equals(origVal));
   short shortVal = mapMessage.getShort("short-type");
   assertEquals((short) 333, shortVal);
   String strVal = mapMessage.getString("string-type");
   assertEquals(TEXT, strVal);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:32,代碼來源:CompressedInteropTest.java

示例4: testCompression

import javax.jms.MapMessage; //導入方法依賴的package包/類
@Test
public void testCompression() throws Exception {

   Connection cconnection = null;
   Connection connection = null;
   try {
      ActiveMQConnectionFactory cfactory = new ActiveMQConnectionFactory("tcp://" + OWHOST + ":" + OWPORT + "");
      cconnection = cfactory.createConnection();
      cconnection.start();
      Session csession = cconnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue cQueue = csession.createQueue(queueName);
      MessageConsumer consumer = csession.createConsumer(cQueue);

      ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://" + OWHOST + ":" + OWPORT + "?jms.useCompression=true");
      connection = factory.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue queue = session.createQueue(queueName);

      MessageProducer producer = session.createProducer(queue);
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

      //text
      TextMessage textMessage = session.createTextMessage();
      textMessage.setText(testString);
      TextMessage receivedMessage = sendAndReceive(textMessage, producer, consumer);

      String receivedText = receivedMessage.getText();
      assertEquals(testString, receivedText);

      //MapMessage
      MapMessage mapMessage = session.createMapMessage();
      mapMessage.setString(testProp, propValue);
      MapMessage receivedMapMessage = sendAndReceive(mapMessage, producer, consumer);
      String value = receivedMapMessage.getString(testProp);
      assertEquals(propValue, value);

      //Object
      ObjectMessage objMessage = session.createObjectMessage();
      objMessage.setObject(testString);
      ObjectMessage receivedObjMessage = sendAndReceive(objMessage, producer, consumer);
      String receivedObj = (String) receivedObjMessage.getObject();
      assertEquals(testString, receivedObj);

      //Stream
      StreamMessage streamMessage = session.createStreamMessage();
      streamMessage.writeString(testString);
      StreamMessage receivedStreamMessage = sendAndReceive(streamMessage, producer, consumer);
      String streamValue = receivedStreamMessage.readString();
      assertEquals(testString, streamValue);

      //byte
      BytesMessage byteMessage = session.createBytesMessage();
      byte[] bytes = testString.getBytes();
      byteMessage.writeBytes(bytes);

      BytesMessage receivedByteMessage = sendAndReceive(byteMessage, producer, consumer);
      long receivedBodylength = receivedByteMessage.getBodyLength();

      assertEquals("bodylength Correct", bytes.length, receivedBodylength);

      byte[] receivedBytes = new byte[(int) receivedBodylength];
      receivedByteMessage.readBytes(receivedBytes);

      String receivedString = new String(receivedBytes);
      assertEquals(testString, receivedString);

      //Message
      Message m = session.createMessage();
      sendAndReceive(m, producer, consumer);
   } finally {
      if (cconnection != null) {
         connection.close();
      }
      if (connection != null) {
         cconnection.close();
      }
   }

}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:80,代碼來源:SimpleOpenWireTest.java


注:本文中的javax.jms.MapMessage.getString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。