Example usage for javax.jms Message setStringProperty

List of usage examples for javax.jms Message setStringProperty

Introduction

In this page you can find the example usage for javax.jms Message 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:com.fusesource.forge.jmstest.tests.AsyncConsumer.java

public void onMessage(Message msg) {
    if (receiveCount != null) {
        receiveCount.incrementAndGet();// w w w . jav a 2 s.co  m
    }
    MessageProducer producer = null;
    try {
        Destination replyDest = msg.getJMSReplyTo();
        if (replyDest != null) {
            Message response = getSession().createTextMessage("Response");
            response.setStringProperty("ServedBy", getName());
            response.setJMSCorrelationID(msg.getJMSCorrelationID());
            for (Enumeration<?> en = msg.getPropertyNames(); en.hasMoreElements();) {
                String key = (String) en.nextElement();
                Object value = msg.getObjectProperty(key);
                if (key.equals("BrokerStamp")) {
                    value = value.toString() + " --";
                }
                response.setObjectProperty(key, value);
            }
            producer = getSession().createProducer(replyDest);
            producer.send(response);
        }
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        if (producer != null) {
            try {
                producer.close();
            } catch (Exception e) {
            }
        }
    }
}

From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.jms.client.OrderTrackingJmsProducerImpl.java

@Override
public String sendMessage(final String activitySummaryMessage) throws OrderTrackingException {
    LOGGER.info("========  sending messge to the JmsQueue Starts===========");
    String deliveryStatus = "";
    final String correlationId = UUID.randomUUID().toString();
    try {/* w  ww.  j a va2 s  .  c o m*/
        getJmsTemplate().send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                MessageConverter messageConverter = jmsTemplate.getMessageConverter();
                Message jmsMessage = messageConverter.toMessage(activitySummaryMessage, session);
                jmsMessage.setStringProperty(properties.getHqLvqName(), activitySummaryMessage);
                jmsMessage.setJMSCorrelationID(correlationId);
                return jmsMessage;
            }
        });

        LOGGER.info("========  sending messge to the JmsQueue Ends===========");
        deliveryStatus = OrderTrackingConstants.MSG_STATUS_SUCCESS;

    } catch (Exception ex) {

        LOGGER.info("====Error occured on sending the message to QUEUE==== " + ex);
        deliveryStatus = OrderTrackingConstants.MSG_STATUS_FAILED;
        throw new OrderTrackingException(OrderTrackingExceptionInfo.FOT006,
                "Error occured while  creating a queue or sending message to the queue.");

    }
    return deliveryStatus;

}

From source file:com.kinglcc.spring.jms.core.converter.GenericJmsMessageConverter.java

private void setConverterOnMessage(Message message, MessageConverter converter) throws JMSException {
    message.setStringProperty(CONVERTER_PROP, converter.getClass().getName());
}

From source file:io.galeb.health.util.CallBackQueue.java

public void update(Target target) {
    String targetStr = new Gson().toJson(target, Target.class);
    jmsTemplate.send(HEALTH_CALLBACK_QUEUE, session -> {
        Message message = session.createObjectMessage(targetStr);
        String uniqueId = "ID:" + target.getName() + "-" + System.currentTimeMillis();
        message.setStringProperty("_HQ_DUPL_ID", uniqueId);
        message.setJMSMessageID(uniqueId);
        message.setStringProperty(HDR_DUPLICATE_DETECTION_ID.toString(), uniqueId);

        logger.info("JMSMessageID: " + uniqueId + " - Target " + target.getName());
        return message;
    });//from w  ww .  j  a  v  a2  s.c  o  m
}

From source file:com.jim.im.message.service.MessageServiceImpl.java

/**
 * @param message ?//from  w ww.ja  va  2  s.  c  om
 */
protected void doSendMq(final ImMessage message) {
    final ActiveMQTopic mqTopicName = new ActiveMQTopic(IMConstant.MQ_FORWARD_TOPIC_NAME);
    MessageConverter messageConverter = jmsTemplate.getMessageConverter();
    jmsTemplate.send(mqTopicName, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            Message innerMessage = messageConverter.toMessage(message, session);
            innerMessage.setStringProperty(IMConstant.IS_FROM_PUSHER, Boolean.TRUE.toString());
            return innerMessage;
        }
    });
}

From source file:org.calrissian.mango.jms.stream.utils.SendReceiveRequestor.java

protected Message populateProperties(Message msg) throws JMSException {
    String recvS = (send) ? recvId : replyToId;
    String replyToS = (send) ? replyToId : recvId;
    msg.setStringProperty(RECV_ID, recvS);
    msg.setStringProperty(REPLYTO_ID, replyToS);
    return msg;//from   ww  w . ja v  a 2 s.  c  om
}

From source file:springchat.service.MessagesServiceImpl.java

@Override
@Secured({ "ROLE_CHATUSER" })
public void postMessage(final String message) {
    jmsTemplate.send("java:comp/env/NewTextMessageChannel", new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            Message notification = session.createMessage();
            Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            notification.setStringProperty("user", auth.getName());
            notification.setLongProperty("date", new Date().getTime());
            notification.setStringProperty("message", message);
            return notification;
        }/* w w  w. ja v  a 2 s.c  o  m*/
    });
}

From source file:org.nuxeo.ecm.core.jms.CoreEventPublisher.java

public void publish(Object content, Topic topic, MessageFactory factory, String eventId) throws JMSException {
    TopicConnection connection = null;// ww  w. j  av  a 2 s .  c o m
    TopicSession session = null;
    TopicPublisher publisher = null;
    try {
        // get a connection from topic connection pool
        connection = getTopicConnection();

        // create a not transacted session
        session = connection.createTopicSession(transacted, TopicSession.AUTO_ACKNOWLEDGE);

        // create the publisher
        publisher = session.createPublisher(topic);
        publisher.setDeliveryMode(isDeliveryPersistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
        publisher.setDisableMessageID(isDisableMessageID);
        publisher.setDisableMessageTimestamp(isDisableMessageTimestamp);
        // create the message using the given factory
        Message msg = factory.createMessage(session, content);
        if (eventId != null) {
            msg.setStringProperty("NuxeoEventId", eventId);
        }
        // publish the message
        publisher.publish(topic, msg);
    } finally {
        if (publisher != null) {
            publisher.close();
        }
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}

From source file:terrastore.event.impl.ActiveMQEventBus.java

private void enqueue(final Event event) {
    String queueName = TERRASTORE_QUEUE_PREFIX + event.getBucket();
    producer.send(queueName, new MessageCreator() {

        @Override/*from  w ww .  ja va 2 s. c  o m*/
        public Message createMessage(Session session) throws JMSException {
            Message message = session.createObjectMessage(event);
            message.setStringProperty("JMSXGroupID", new StringBuilder().append(event.getBucket()).append(":")
                    .append(event.getKey()).toString());
            return message;
        }

    });
}

From source file:cherry.foundation.async.PropertyMessagePostProcessor.java

@Override
public Message postProcessMessage(Message message) throws JMSException {
    for (Map.Entry<String, Object> entry : properties.entrySet()) {
        String name = entry.getKey();
        Object v = entry.getValue();
        if (v instanceof String) {
            message.setStringProperty(name, (String) v);
        } else if (v instanceof Integer) {
            message.setIntProperty(name, ((Integer) v).intValue());
        } else if (v instanceof Long) {
            message.setLongProperty(name, ((Long) v).longValue());
        } else if (v instanceof Short) {
            message.setShortProperty(name, ((Short) v).shortValue());
        } else if (v instanceof Byte) {
            message.setByteProperty(name, ((Byte) v).byteValue());
        } else if (v instanceof Boolean) {
            message.setBooleanProperty(name, ((Boolean) v).booleanValue());
        } else if (v instanceof Double) {
            message.setDoubleProperty(name, ((Double) v).doubleValue());
        } else if (v instanceof Float) {
            message.setFloatProperty(name, ((Float) v).floatValue());
        } else {//w  w  w  .ja  v  a  2  s.c  o m
            message.setObjectProperty(name, v);
        }
    }
    return message;
}