Example usage for javax.jms TextMessage getText

List of usage examples for javax.jms TextMessage getText

Introduction

In this page you can find the example usage for javax.jms TextMessage getText.

Prototype


String getText() throws JMSException;

Source Link

Document

Gets the string containing this message's data.

Usage

From source file:com.oneops.controller.jms.InductorListenerTest.java

@Test
/** test the message impl */
public void testListening() throws JMSException {
    try {/*  www.  j a  v  a 2  s.  co m*/
        listener.init();

        TextMessage message = mock(TextMessage.class);
        when(message.getText()).thenReturn("{messgetext:true}");
        when(message.getStringProperty("task_id")).thenReturn("corel-id");
        when(message.getStringProperty("task_result_code")).thenReturn("200");
        when(message.getStringProperty("type")).thenReturn("deploybom");
        when(message.getJMSCorrelationID()).thenReturn("jms|cor!rel!ation!id");

        listener.onMessage(message);
        listener.cleanup();
        listener.getConnectionStats();
    } catch (JMSException e) {
        System.out.println("CAUTH EXCEPTION " + e.getMessage());
        e.printStackTrace();
        throw e;
    }

}

From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueSendReceiveTest.java

@Test
public void testReceive() throws Exception {
    Connection connection = activeMQConnectionFactory.createConnection();
    connection.start();//  ww  w. j  a  va 2 s.c o m
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(activeMQTestQueueA);
    Message rawMessage = consumer.receive();
    assertTrue(rawMessage instanceof TextMessage);

    TextMessage message = (TextMessage) rawMessage;
    assertEquals("test text", message.getText());
    connection.close();
}

From source file:sk.seges.test.jms.multiple.QueueSendReceiveTest.java

@Test
public void testReceive() throws Exception {
    Connection connection = testConnectionFactory.createConnection();
    connection.start();//  ww  w.  ja  v a2s .com
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(testQueueA);
    Message rawMessage = consumer.receive();
    assertTrue(rawMessage instanceof TextMessage);

    TextMessage message = (TextMessage) rawMessage;
    assertEquals("test text", message.getText());
    connection.close();
}

From source file:org.vbossica.azurebox.servicebus.amqp_1_0.ClientConnectionIT.java

@Test
public void send_and_receive_with_destination() throws Exception {
    template.send(destination, new MessageCreator() {
        @Override/*from w w  w  .ja  v a 2s .  com*/
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage("hello world (2)");
        }
    });
    TextMessage msg = (TextMessage) template.receive(destination);
    System.out.println(msg.getText());
}

From source file:org.sample.send.receive.MessageReceiverAsync.java

@Override
public void onMessage(Message message) {
    try {//from  w  ww. ja  v a  2s  . co m
        TextMessage tm = (TextMessage) message;
        System.out.println("Message received (async): " + tm.getText());
    } catch (JMSException ex) {
        Logger.getLogger(MessageReceiverAsync.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:org.vbossica.azurebox.servicebus.amqp_1_0.ClientConnectionIT.java

@Test
public void send_and_receive() throws Exception {
    template.send(destinationName, new MessageCreator() {
        @Override//from  ww w  .  j  a va  2s  .  c  o  m
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage("hello world");
        }
    });
    TextMessage msg = (TextMessage) template.receive(destinationName);
    System.out.println(msg.getText());
}

From source file:org.dataminx.dts.ws.jms.DtsWsMessageConverter.java

/**
 * Extracts the given JMS Message payload and returns it as an object.
 *
 * @param message the incoming JMS message
 * @return the message payload as an {@link Object}
 * @throws JMSException if the incoming message is not of a supported
 *         message type// w  ww . ja v  a  2 s. com
 */
private Object extractMessagePayload(final Message message) throws JMSException {
    final Object payload;
    if (message instanceof TextMessage) {
        final TextMessage textMessage = (TextMessage) message;
        payload = textMessage.getText();
    } else if (message instanceof ObjectMessage) {
        final ObjectMessage objectMessage = (ObjectMessage) message;
        payload = objectMessage.getObject();
    } else if (message instanceof BytesMessage) {
        final BytesMessage bytesMessage = (BytesMessage) message;
        final byte[] bytes = new byte[(int) bytesMessage.getBodyLength()];
        bytesMessage.readBytes(bytes);
        final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        payload = new StreamSource(bis);
    } else {
        throw new MessageConversionException("Invalid message type...");
    }
    return payload;
}

From source file:org.hoteia.qalingo.core.jms.cacheflush.listener.CacheFlushQueueListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *//*from  w  w  w .  j a  v  a 2 s.c  o m*/
public void onMessage(Message message) {
    try {
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String valueJMSMessage = tm.getText();

            if (StringUtils.isNotEmpty(valueJMSMessage)) {
                final CacheFlushMessageJms cacheFlushMessageJms = xmlMapper.getXmlMapper()
                        .readValue(valueJMSMessage, CacheFlushMessageJms.class);

                cacheService.flushCacheEntity(cacheFlushMessageJms.getObjectClass(),
                        cacheFlushMessageJms.getObjectId().toString());

                if (logger.isDebugEnabled()) {
                    logger.debug("Processed message, value: " + valueJMSMessage);
                }
            } else {
                logger.warn("Cache Flush: Jms Message is empty");
            }
        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:samples.SpringJmsConsumer.java

@Override
public void onMessage(Message message) {
    try {//  w w w.  java2  s.c o m
        if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            System.out.println("Received Text Message: " + textMessage.getText());
        } else {
            System.out.println("Received Non-Text Message: " + message);
        }
    } catch (JMSException ex) {
        ex.printStackTrace();
    }
}

From source file:com.martian.apps.springlab.springactivemq.service.MessageConsumer.java

public String receiveMessage() throws JMSException {
    TextMessage textMessage = (TextMessage) jmsTemplate.receive(destination);
    LOG.info("Consumer receive: " + textMessage);
    return textMessage.getText();
}