Example usage for javax.jms ObjectMessage setStringProperty

List of usage examples for javax.jms ObjectMessage setStringProperty

Introduction

In this page you can find the example usage for javax.jms ObjectMessage 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.alliander.osgp.adapter.ws.microgrids.infra.jms.MicrogridsRequestMessageSender.java

/**
 * Method for sending a request message to the microgrids requests queue
 *
 * @param requestMessage//from   w ww. j  ava 2 s. c om
 *            The MicrogridsRequestMessage request message to send.
 */
private void sendMessage(final MicrogridsRequestMessage requestMessage) {
    LOGGER.info("Sending message to the microgrids requests queue");

    this.microgridsRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage.getRequest());
            objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
            objectMessage.setJMSType(requestMessage.getMessageType().toString());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION,
                    requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION,
                    requestMessage.getDeviceIdentification());
            return objectMessage;
        }
    });
}

From source file:com.alliander.osgp.adapter.ws.smartmetering.infra.jms.SmartMeteringRequestMessageSender.java

/**
 * Method for sending a request message to the public lighting requests
 * queue/*from w  w w .j  a  v  a  2s.  c  o  m*/
 *
 * @param requestMessage
 *            The SmartMeteringRequestMessage request message to send.
 */
private void sendMessage(final SmartMeteringRequestMessage requestMessage) {
    LOGGER.info("Sending message to the smart metering requests queue");

    this.smartMeteringRequestsJmsTemplate.setPriority(requestMessage.getMessagePriority());
    this.smartMeteringRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage.getRequest());
            objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
            objectMessage.setJMSType(requestMessage.getMessageType().toString());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION,
                    requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION,
                    requestMessage.getDeviceIdentification());
            if (requestMessage.getScheduleTime() != null) {
                objectMessage.setLongProperty(Constants.SCHEDULE_TIME, requestMessage.getScheduleTime());
            }
            return objectMessage;
        }
    });
}

From source file:com.alliander.osgp.adapter.ws.core.infra.jms.CommonRequestMessageSender.java

/**
 * Method for sending a request message to the public lighting requests
 * queue//from ww  w. j a  v a  2  s . c  o m
 *
 * @param requestMessage
 *            The CommonRequestMessage request message to send.
 */
private void sendMessage(final CommonRequestMessage requestMessage) {
    LOGGER.info("Sending request message to common requests queue");

    this.commonRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage.getRequest());
            objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
            objectMessage.setJMSType(requestMessage.getMessageType().toString());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION,
                    requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION,
                    requestMessage.getDeviceIdentification());
            if (requestMessage.getScheduleTime() != null) {
                objectMessage.setLongProperty(Constants.SCHEDULE_TIME,
                        requestMessage.getScheduleTime().getMillis());
            }
            return objectMessage;
        }

    });
}

From source file:com.alliander.osgp.adapter.ws.publiclighting.infra.jms.PublicLightingRequestMessageSender.java

/**
 * Method for sending a request message to the public lighting requests
 * queue/*  www  .ja v  a  2 s.co  m*/
 *
 * @param requestMessage
 *            The PublicLightingRequestMessage request message to send.
 */
private void sendMessage(final PublicLightingRequestMessage requestMessage) {
    LOGGER.info("Sending message to the public lighting requests queue");

    this.publicLightingRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage.getRequest());
            objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
            objectMessage.setJMSType(requestMessage.getMessageType().toString());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION,
                    requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION,
                    requestMessage.getDeviceIdentification());
            if (requestMessage.getScheduleTime() != null) {
                objectMessage.setLongProperty(Constants.SCHEDULE_TIME,
                        requestMessage.getScheduleTime().getMillis());
            }
            return objectMessage;
        }

    });
}

From source file:com.alliander.osgp.adapter.ws.tariffswitching.infra.jms.TariffSwitchingRequestMessageSender.java

/**
 * Method for sending a request message to the public lighting requests
 * queue//from w  w  w. j a va2 s.  c om
 *
 * @param requestMessage
 *            The TariffSwitchingRequestMessage request message to send.
 */
private void sendMessage(final TariffSwitchingRequestMessage requestMessage) {
    LOGGER.info("Sending message to the tariff switching requests queue");

    this.tariffSwitchingRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage.getRequest());
            objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
            objectMessage.setJMSType(requestMessage.getMessageType().toString());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION,
                    requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION,
                    requestMessage.getDeviceIdentification());
            if (requestMessage.getScheduleTime() != null) {
                objectMessage.setLongProperty(Constants.SCHEDULE_TIME,
                        requestMessage.getScheduleTime().getMillis());
            }
            return objectMessage;
        }

    });
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.SigningServerRequestMessageSender.java

public void send(final RequestMessage requestMessage, final String messageType) {
    LOGGER.info("Sending request message to signing server, with reply-to-queue: {}.",
            this.replyToQueue.toString());

    this.signingServerRequestsJmsTemplate.send(new MessageCreator() {

        @Override//from w  w  w  .  j a v  a 2  s .  c om
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
            objectMessage.setJMSType(messageType);
            objectMessage.setJMSReplyTo(SigningServerRequestMessageSender.this.replyToQueue);
            objectMessage.setJMSCorrelationID(requestMessage.getCorrelationUid());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION,
                    requestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION,
                    requestMessage.getDeviceIdentification());

            return objectMessage;
        }

    });
}

From source file:com.oneops.daq.jms.SensorPublisher.java

/**
 * Publish message./*w  w  w .j a va  2 s.  c om*/
 *
 * @param event the event
 * @throws JMSException the jMS exception
 */
public void publishMessage(final BasicEvent event) throws JMSException {

    if (System.currentTimeMillis() > lastFailureTimestamp) {
        int shard = (int) (event.getManifestId() % poolsize);
        try {
            producers[shard].send(session -> {
                ObjectMessage message = session.createObjectMessage(event);
                message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
                message.setLongProperty("ciId", event.getCiId());
                message.setLongProperty("manifestId", event.getManifestId());
                message.setStringProperty("source", event.getSource());
                if (logger.isDebugEnabled()) {
                    logger.debug("Published: ciId:" + event.getCiId() + "; source:" + event.getSource());
                }
                return message;
            });
            lastFailureTimestamp = -1;
        } catch (JmsException exception) {
            logger.warn("There was an error sending a message. Discarding messages for " + mqConnectionThreshold
                    + " ms");
            lastFailureTimestamp = System.currentTimeMillis() + mqConnectionThreshold;
        }
    }
}

From source file:nl.nn.adapterframework.jms.JmsTransactionalStorage.java

public String storeMessage(String messageId, String correlationId, Date receivedDate, String comments,
        String label, Serializable message) throws SenderException {
    Session session = null;/*  www .  j  a  v a  2 s. c  om*/
    try {
        session = createSession();
        ObjectMessage msg = session.createObjectMessage(message);
        msg.setStringProperty(FIELD_TYPE, getType());
        msg.setStringProperty(FIELD_ORIGINAL_ID, messageId);
        msg.setJMSCorrelationID(correlationId);
        msg.setLongProperty(FIELD_RECEIVED_DATE, receivedDate.getTime());
        msg.setStringProperty(FIELD_COMMENTS, comments);
        if (StringUtils.isNotEmpty(getSlotId())) {
            msg.setStringProperty(FIELD_SLOTID, getSlotId());
        }
        msg.setStringProperty(FIELD_LABEL, label);
        return send(session, getDestination(), msg);
    } catch (Exception e) {
        throw new SenderException(e);
    } finally {
        closeSession(session);
    }
}

From source file:org.apache.synapse.message.store.impl.jms.JmsProducer.java

public boolean storeMessage(MessageContext synCtx) {
    if (synCtx == null) {
        return false;
    }//from  w  ww  .  j a va  2 s  .  c  o  m
    if (!checkConnection()) {
        logger.warn(getId() + ". Ignored MessageID : " + synCtx.getMessageID());
        return false;
    }
    StorableMessage message = MessageConverter.toStorableMessage(synCtx);
    boolean error = false;
    Throwable throwable = null;
    try {
        ObjectMessage objectMessage = session.createObjectMessage(message);
        objectMessage.setStringProperty(OriginalMessageID, synCtx.getMessageID());
        setPriority(producer, objectMessage, message);
        setJmsProducerProperties(producer, synCtx);
        setJmsMessageProperties(objectMessage, synCtx);
        setTransportHeaders(objectMessage, synCtx);
        producer.send(objectMessage);

        if (session.getTransacted()) {
            session.commit();
        }

    } catch (JMSException e) {
        throwable = e;
        error = true;
        isConnectionError = true;

        try {

            if (session.getTransacted()) {
                session.rollback();
            }

        } catch (JMSException ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("Fail to rollback message [" + synCtx.getMessageID() + "] from the message store "
                        + ":" + store.getName());
            }
        }

    } catch (Throwable t) {
        throwable = t;
        error = true;

        try {

            if (session.getTransacted()) {
                session.rollback();
            }

        } catch (JMSException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Fail to rollback message [" + synCtx.getMessageID() + "] from the message store "
                        + ":" + store.getName());
            }
        }
    }

    if (error) {
        String errorMsg = getId() + ". Ignored MessageID : " + synCtx.getMessageID()
                + ". Could not store message to store [" + store.getName() + "]. Error:"
                + throwable.getLocalizedMessage();
        logger.error(errorMsg, throwable);
        store.closeWriteConnection();
        connection = null;
        if (logger.isDebugEnabled()) {
            logger.debug(getId() + ". Ignored MessageID : " + synCtx.getMessageID());
        }
        return false;
    } else {
        store.cleanup(null, session, false);
    }
    if (logger.isDebugEnabled()) {
        logger.debug(getId() + ". Stored MessageID : " + synCtx.getMessageID());
    }
    store.enqueued();
    return true;
}

From source file:org.grouter.common.jms.QueueSenderDestination.java

/**
 * Helper method that simply puts key value pairs into the JMS header.
 *
 * @param message a serializable object instance
 * @param headerProperties properties to store in header for JMS message
 *
 * @return ObjectMessage an object message
 *//*  w  w w . j a  v  a 2s  .  c  om*/
private ObjectMessage createMessage(Serializable message, HashMap<String, String> headerProperties) {
    ObjectMessage msg = null;
    try {
        msg = this.queueSession.createObjectMessage(message);
        msg.clearProperties();
        if (headerProperties != null) {
            for (String key : headerProperties.keySet()) {
                String value = headerProperties.get(key);
                msg.setStringProperty(key, value);
            }
        }
    } catch (JMSException e) {
        logger.warn("Failed setting header for message.", e);
    }
    return msg;
}