Example usage for javax.jms TextMessage setText

List of usage examples for javax.jms TextMessage setText

Introduction

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

Prototype


void setText(String string) throws JMSException;

Source Link

Document

Sets the string containing this message's data.

Usage

From source file:org.wso2.carbon.integration.test.client.JMSPublisherClient.java

/**
 * Each message will be divided into groups and create the map message
 *
 * @param producer     Used for sending messages to a destination
 * @param session      Used to produce the messages to be sent
 * @param messagesList List of messages to be sent
 *
 *///www. ja v  a2  s.c  o m
public static void publishTextMessage(MessageProducer producer, Session session, List<String> messagesList)
        throws JMSException {
    for (String message : messagesList) {
        TextMessage jmsTextMessage = session.createTextMessage();
        jmsTextMessage.setText(message);
        producer.send(jmsTextMessage);
    }
}

From source file:org.firstopen.singularity.util.JMSUtil.java

public static void deliverMessageToTopic(String host, String topicName, String xml) {
    log.debug("IntegrationMod.deliverMessageToQueue queueName = " + topicName + " and doc = " + xml);

    char test = topicName.charAt(0);

    if (test == '/')
        topicName = topicName.substring(1);

    try {/*from  w w w .j a v  a 2 s . co m*/

        InitialContext context = JNDIUtil.getInitialContext(host);

        Connection connection = null;
        Session session = null;
        MessageProducer publisher = null;
        ConnectionFactory tcf = (ConnectionFactory) context.lookup("ConnectionFactory");

        Topic topic = (Topic) context.lookup(topicName);

        connection = tcf.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        publisher = session.createProducer(topic);

        TextMessage message = session.createTextMessage();

        log.debug("message value is -> " + xml);

        message.setText(xml);

        publisher.send(message);

    } catch (Exception e) {
        log.error("unable to send message on topic", e);
    } finally {

    }
}

From source file:org.firstopen.singularity.util.JMSUtil.java

public static void deliverMessageToQueue(String host, String queueName, String xml) {
    log.debug("IntegrationMod.deliverMessageToQueue queueName = " + queueName + " and doc = " + xml);
    MessageProducer m_sender = null;/* w  w w  .  j  av  a 2 s.  c  om*/
    Session m_session = null;
    Connection connection = null;

    char test = queueName.charAt(0);

    if (test == '/')
        queueName = queueName.substring(1);

    try {

        InitialContext context = JNDIUtil.getInitialContext(host);

        ConnectionFactory qcf = (ConnectionFactory) context.lookup("ConnectionFactory");

        Queue queue = (Queue) context.lookup("queue/" + queueName);

        connection = qcf.createConnection();

        m_session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        m_sender = m_session.createProducer(queue);

        TextMessage message = m_session.createTextMessage();

        log.debug("message value is -> " + xml);

        message.setText(xml);

        m_sender.send(message);

    } catch (Exception e) {
        log.error("IntegrationMod.deliverMessageToQueue() Exception = ", e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.error("unable ot close JMS Connection", e);
            }
        }
    }
}

From source file:unic.mentoring.jms.ctrl.MessageCtrl.java

protected void sendMessage(String message, String topicName) throws JMSException {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    Connection connection = connectionFactory.createConnection();
    connection.start();//  w  ww.j av a 2  s  . c  om

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTopic(topicName);
    MessageProducer producer = session.createProducer(topic);
    TextMessage jmsMessage = session.createTextMessage();
    jmsMessage.setText(message);

    producer.send(jmsMessage);
    connection.close();
}

From source file:org.acruxsource.sandbox.spring.jmstows.jms.JmsMessageSender.java

public void sendMessage(String destination, final String message) {
    jmsTemplate.send(destination, new MessageCreator() {

        @Override/*from ww  w . ja  va2s . c om*/
        public Message createMessage(Session session) throws JMSException {
            TextMessage textMessage = session.createTextMessage();
            textMessage.setText(message);
            return textMessage;
        }
    });
}

From source file:org.apache.storm.jms.spout.JmsSpoutTest.java

public Message sendMessage(ConnectionFactory connectionFactory, Destination destination) throws JMSException {
    Session mySess = connectionFactory.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
    MessageProducer producer = mySess.createProducer(destination);
    TextMessage msg = mySess.createTextMessage();
    msg.setText("Hello World");
    log.debug("Sending Message: " + msg.getText());
    producer.send(msg);/*  w w  w. ja v a2  s  . c o  m*/
    return msg;
}

From source file:org.btc4j.jms.BtcDaemonCaller.java

public void send(String destination, final String payload) {
    jmsTemplate.convertAndSend(destination, new MessageCreator() {
        @Override/* ww w.j a  v a 2 s  .c  o m*/
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage();
            message.setText(payload);
            message.setStringProperty("btcapi:account", account);
            message.setStringProperty("btcapi:password", password);
            return message;
        }
    });
}

From source file:org.openadaptor.auxil.connector.jms.DefaultMessageGenerator.java

public Message createMessage(Object messageRecord, Session session) throws JMSException {
    Message msg;//from w w  w  . j a va2s. c o  m
    if (messageRecord instanceof String) {
        TextMessage textMsg = session.createTextMessage();
        textMsg.setText((String) messageRecord);
        msg = textMsg;
    } else if (messageRecord instanceof Serializable) {
        ObjectMessage objectMsg = session.createObjectMessage();
        objectMsg.setObject((Serializable) messageRecord);
        msg = objectMsg;
    } else {
        // We have not needed more message types in practice.
        // If we do need them in future this is where they go.
        throw new RecordFormatException(
                "Undeliverable record type [" + messageRecord.getClass().getName() + "]");
    }
    setMessageProperties(msg);
    return msg;
}

From source file:org.apache.activemq.JmsTopicSendSameMessageTest.java

public void testSendReceive() throws Exception {
    messages.clear();/*from   w w w .j a va  2s .co m*/

    TextMessage message = session.createTextMessage();

    for (int i = 0; i < data.length; i++) {
        message.setText(data[i]);
        message.setStringProperty("stringProperty", data[i]);
        message.setIntProperty("intProperty", i);

        if (verbose) {
            LOG.info("About to send a message: " + message + " with text: " + data[i]);
        }

        producer.send(producerDestination, message);
    }

    assertMessagesAreReceived();
}

From source file:fi.vm.sade.log.client.LoggerJms.java

@Override
public void log(final Tapahtuma tapahtuma) {

    log.debug("log({})", tapahtuma);

    if (jmsTemplate == null) {
        throw new IllegalStateException("LoggerJms - invalid configuration 'jsmTemplate' not available!");
    }/*from  www.j  a v  a2  s  .c  o m*/

    final LogEvent event = new LogEvent(tapahtuma);

    // Convert message to TextMessage with LogEvent as XML in payload
    jmsTemplate.send(new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage();
            message.setText(encode(event));
            log.debug("  sending log message - text={}", message.getText());
            return message;
        }
    });

}