Example usage for javax.jms TextMessage setStringProperty

List of usage examples for javax.jms TextMessage setStringProperty

Introduction

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

Prototype


void setStringProperty(String name, String value) throws JMSException;

Source Link

Document

Sets a String property value with the specified name into the message.

Usage

From source file:org.ala.jms.JmsMessageProducer.java

/**
 * Generates JMS messages// w  ww.j a  va2 s.c o  m
 */
@Test
public void generateCreateMessage() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = getJson("" + myGuid);
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD,
                    JmsMessageListener.Method.CREATE.toString());
            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }
    });
}

From source file:org.ala.jms.JmsMessageProducer.java

@Test
public void generateUpdateMessage() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = getJson("" + myGuid);
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD,
                    JmsMessageListener.Method.UPDATE.toString());

            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }/*from   w w w.j ava  2s .c om*/
    });
}

From source file:org.ala.jms.JmsMessageProducer.java

@Test
public void generateDeleteMessage() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = getJson("" + myGuid);
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD,
                    JmsMessageListener.Method.DELETE.toString());

            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }//  w  w  w .ja  v  a2  s.  c  o m
    });
}

From source file:org.ala.jms.JmsMessageProducer.java

@Test
public void generateInvalidMessage() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = "";
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD,
                    JmsMessageListener.Method.CREATE.toString());

            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }//from w ww  . j  a v a  2s . c  om
    });
}

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

public String sendReceive(final String destination, final String payload) {
    return jmsTemplate.execute(new SessionCallback<String>() {
        @Override//from w  w  w  . j  a  v a  2  s  . c om
        public String doInJms(Session session) throws JMSException {
            final TemporaryQueue replyQueue = session.createTemporaryQueue();
            jmsTemplate.send(destination, new MessageCreator() {
                @Override
                public Message createMessage(Session session) throws JMSException {
                    TextMessage message = session.createTextMessage();
                    message.setJMSReplyTo(replyQueue);
                    message.setText(payload);
                    message.setStringProperty("btcapi:account", account);
                    message.setStringProperty("btcapi:password", password);
                    return message;
                }
            });
            return String.valueOf(jmsTemplate.receiveAndConvert(replyQueue));
        }
    });
}

From source file:org.hawkular.apm.server.jms.AbstractPublisherJMS.java

/**
 * This method publishes the supplied items.
 *
 * @param tenantId The tenant id//from w  ww .  j av a  2  s.com
 * @param items The items
 * @param subscriber The optional subscriber name
 * @param retryCount The retry count
 * @param delay The delay
 * @throws Exception Failed to publish
 */
protected void doPublish(String tenantId, List<T> items, String subscriber, int retryCount, long delay)
        throws Exception {
    String data = mapper.writeValueAsString(items);

    TextMessage tm = session.createTextMessage(data);

    if (tenantId != null) {
        tm.setStringProperty("tenant", tenantId);
    }

    if (subscriber != null) {
        tm.setStringProperty("subscriber", subscriber);
    }

    tm.setIntProperty("retryCount", retryCount);

    if (delay > 0) {
        tm.setLongProperty("_AMQ_SCHED_DELIVERY", System.currentTimeMillis() + delay);
    }

    if (log.isLoggable(Level.FINEST)) {
        log.finest("Publish: " + tm);
    }

    producer.send(tm);
}

From source file:org.addsimplicity.anicetus.io.jms.JsonMessageConverter.java

/**
 * Translate the telemetry to a JMS message. A JMS text message is used to
 * contain the translated payload./*w  ww . j a v a2 s.com*/
 * 
 * @param obj
 *          The telemetry artifact.
 * @param jsmSess
 *          The JMS session.
 * @return a text message containing the translated payload.
 * 
 * @see org.springframework.jms.support.converter.MessageConverter#toMessage(java.lang.Object,
 *      javax.jms.Session)
 */
public Message toMessage(Object obj, Session jmsSess) throws JMSException, MessageConversionException {
    TextMessage m = jmsSess.createTextMessage();

    GlobalInfo telemetry = (GlobalInfo) obj;
    m.setJMSCorrelationID(telemetry.getEntityId().toString());
    m.setStringProperty(GlobalInfoFields.ReportingNode.name(), telemetry.getReportingNode());

    if (telemetry.containsKey(ExecInfoFields.OperationName.name())) {
        m.setStringProperty(ExecInfoFields.OperationName.name(),
                (String) telemetry.get(ExecInfoFields.OperationName.name()));
    }

    if (telemetry.containsKey(ExecInfoFields.Status.name())) {
        m.setStringProperty(ExecInfoFields.Status.name(),
                telemetry.get(ExecInfoFields.Status.name()).toString());
    }

    char[] body = m_translator.encode(telemetry);

    m.setText(new String(body));

    return m;
}

From source file:it.cnr.isti.labse.glimpse.manager.GlimpseManager.java

private TextMessage createMessage(String msg, String sender) {
    try {/*from   w  ww . j a v  a  2  s. com*/
        TextMessage sendMessage = publishSession.createTextMessage();
        sendMessage.setText(msg);
        sendMessage.setStringProperty("DESTINATION", sender);
        return sendMessage;
    } catch (JMSException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.marketcetera.client.jms.JMSXMLMessageConverter.java

/**
 * Converts a messaging object to a JMS Message.
 *
 * @param inObject the message to be converted. It should either be
 * an order or a report.//from ww  w. j av  a2 s  .c  om
 * @param session the JMS Session instance.
 *
 * @return the JMS message.
 *
 * @throws javax.jms.JMSException if there were errors serializing the
 * messaging object.
 * @throws org.springframework.jms.support.converter.MessageConversionException if the supplied object was not
 * an acceptable messaging object.
 */
@Override
public Message toMessage(Object inObject, Session session) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting to JMS {}", inObject); //$NON-NLS-1$
    if ((inObject instanceof ReportBaseImpl) || (inObject instanceof FIXResponseImpl)
            || (inObject instanceof OrderEnvelope) || (inObject instanceof BrokerStatus)) {
        try {
            TextMessage message = session.createTextMessage(toXML(inObject));
            //Set the type property for interoperability with .NET client.
            message.setStringProperty(JMS_TYPE_PROPERTY, inObject.getClass().getSimpleName());
            return message;
        } catch (JAXBException e) {
            throw new MessageConversionException(new I18NBoundMessage1P(
                    Messages.ERROR_CONVERTING_OBJECT_TO_MESSAGE, ObjectUtils.toString(inObject)).getText(), e);
        }
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_TO_SEND, ObjectUtils.toString(inObject))
                        .getText());
    }
}

From source file:eu.learnpad.simulator.mon.manager.GlimpseManager.java

private TextMessage createMessage(String msg, String sender) {
    try {// w  w  w .  j  ava  2 s  .  c om
        TextMessage sendMessage = publishSession.createTextMessage();
        sendMessage.setText(msg);
        sendMessage.setStringProperty("DESTINATION", sender);
        sendMessage.setBooleanProperty("ISASCORE", false);
        return sendMessage;
    } catch (JMSException e) {
        e.printStackTrace();
        return null;
    }
}