Example usage for javax.jms ObjectMessage setLongProperty

List of usage examples for javax.jms ObjectMessage setLongProperty

Introduction

In this page you can find the example usage for javax.jms ObjectMessage setLongProperty.

Prototype


void setLongProperty(String name, long value) throws JMSException;

Source Link

Document

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

Usage

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

/**
 * Publish message./* w  w w.j  av a  2 s  .c o m*/
 *
 * @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:com.alliander.osgp.adapter.ws.smartmetering.infra.jms.SmartMeteringRequestMessageSender.java

/**
 * Method for sending a request message to the public lighting requests
 * queue/*from  w ww . jav  a2 s .c  om*/
 *
 * @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/*w w w.  ja va2 s  . c  om*/
 *
 * @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//w w  w .  ja va  2  s. c  o 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// w ww.j av  a 2  s  .c o  m
 *
 * @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: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;/*w  ww.  j av  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.jbpm.bpel.integration.server.SoapHandler.java

protected ObjectMessage sendRequest(SOAPMessage soapMessage, Session jmsSession, JbpmContext jbpmContext)
        throws SOAPException, JMSException {
    // create a jms message to deliver the incoming content
    ObjectMessage jmsRequest = jmsSession.createObjectMessage();

    // put the partner link identified by handle in a jms property
    PartnerLinkEntry partnerLinkEntry = integrationControl.getPartnerLinkEntry(portTypeName, serviceName,
            portName);/*from  w  ww  .  java2s.c om*/
    long partnerLinkId = partnerLinkEntry.getId();
    jmsRequest.setLongProperty(IntegrationConstants.PARTNER_LINK_ID_PROP, partnerLinkId);

    Operation operation = determineOperation(soapMessage);
    if (operation == null)
        throw new SOAPException("could not determine operation to perform");

    // put the operation name in a jms property
    String operationName = operation.getName();
    jmsRequest.setStringProperty(IntegrationConstants.OPERATION_NAME_PROP, operationName);

    log.debug("received request: partnerLink=" + partnerLinkId + ", operation=" + operationName);

    // extract message content
    HashMap requestParts = new HashMap();
    formatter.readMessage(operationName, soapMessage, requestParts, MessageDirection.INPUT);
    jmsRequest.setObject(requestParts);

    // fill message properties
    BpelProcessDefinition process = integrationControl.getDeploymentDescriptor()
            .findProcessDefinition(jbpmContext);
    MessageType requestType = process.getImportDefinition()
            .getMessageType(operation.getInput().getMessage().getQName());
    fillCorrelationProperties(requestParts, jmsRequest, requestType.getPropertyAliases());

    // set up producer
    MessageProducer producer = jmsSession.createProducer(partnerLinkEntry.getDestination());
    try {
        // is the exchange pattern request/response?
        if (operation.getOutput() != null) {
            Destination replyTo = integrationControl.getIntegrationServiceFactory().getResponseDestination();
            jmsRequest.setJMSReplyTo(replyTo);

            // have jms discard request message if response timeout expires
            Number responseTimeout = getResponseTimeout(jbpmContext);
            if (responseTimeout != null)
                producer.setTimeToLive(responseTimeout.longValue());
        } else {
            // have jms discard message if one-way timeout expires
            Number oneWayTimeout = getOneWayTimeout(jbpmContext);
            if (oneWayTimeout != null)
                producer.setTimeToLive(oneWayTimeout.longValue());
        }

        // send request message
        producer.send(jmsRequest);
        log.debug("sent request: " + RequestListener.messageToString(jmsRequest));

        return jmsRequest;
    } finally {
        // release producer resources
        producer.close();
    }
}