Example usage for javax.jms Session createTextMessage

List of usage examples for javax.jms Session createTextMessage

Introduction

In this page you can find the example usage for javax.jms Session createTextMessage.

Prototype


TextMessage createTextMessage(String text) throws JMSException;

Source Link

Document

Creates an initialized TextMessage object.

Usage

From source file:org.genemania.connector.JmsEngineConnector.java

@Cacheable(cacheName = "searchResultsCache", keyGenerator = @KeyGenerator(name = "StringCacheKeyGenerator"))
public RelatedGenesWebResponseDto getRelatedGenes(final RelatedGenesWebRequestDto dto)
        throws ApplicationException {
    final String rgcid = String.valueOf(System.currentTimeMillis());
    RelatedGenesWebResponseDto ret = new RelatedGenesWebResponseDto();
    jmsTemplate.send(requestQueue, new MessageCreator() {
        public TextMessage createMessage(Session session) throws JMSException {
            LOG.debug("sending GetRelatedGenesMessage request to " + requestQueue.getQueueName());
            RelatedGenesRequestMessage request = BrokerUtils.dto2msg(dto);
            TextMessage ret = session.createTextMessage(request.toXml());
            ret.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
            ret.setJMSType(MessageType.RELATED_GENES.getCode());
            replyQueue = session.createTemporaryQueue();
            ret.setJMSReplyTo(replyQueue);
            ret.setJMSCorrelationID(rgcid);
            LOG.debug("getRelatedGenes waiting for reply on " + replyQueue.getQueueName());
            return ret;
        }//w ww .  java2  s. co m
    });
    sentMessages++;
    Message response;
    try {
        response = jmsTemplate.receive(replyQueue);
        receivedMessages++;
        if (response == null) {
            LOG.error("getRelatedGenes JMS response is null");
        } else if (!response.getJMSCorrelationID().equals(rgcid)) {
            LOG.error("JMS response id does not match request, sent " + rgcid + ", recieved "
                    + response.getJMSCorrelationID() + ", dropping response.");
        } else {
            LOG.debug("getRelatedGenes reply received");
            String responseBody = ((TextMessage) response).getText();
            if (StringUtils.isNotEmpty(responseBody)) {
                RelatedGenesResponseMessage responseMessage = RelatedGenesResponseMessage.fromXml(responseBody);
                LOG.debug("finished fromXml");
                LOG.debug("num attributes in response message: " + responseMessage.getAttributes().size());
                if (responseMessage.getErrorCode() == 0) {
                    // friendlyPrintNetworks("networks in response message: ",
                    // responseMessage.getNetworks());
                    // friendlyPrintCategories("categories in response message: ",
                    // responseMessage.getAnnotations());
                    RelatedGenesWebResponseDto hollowResponseDto = BrokerUtils.msg2dto(responseMessage);
                    LOG.debug("finished msg2dto");
                    ret = load(hollowResponseDto);
                    LOG.debug("finished hollowResponseDto");
                } else {
                    LOG.error(responseMessage.getErrorMessage());
                    appErrors++;
                    throw new ApplicationException(responseMessage.getErrorMessage(),
                            responseMessage.getErrorCode());
                }
            } else {
                LOG.error("getRelatedGenes empty response body");
            }
        }
        processedMessages++;
    } catch (JMSException e) {
        LOG.error("getRelatedGenes JMSException: " + e.getMessage());
        errors++;
        throw new ApplicationException(Constants.ERROR_CODES.APPLICATION_ERROR);
    } catch (DataStoreException e) {
        LOG.error("getRelatedGenes DataStoreException: " + e.getMessage());
        errors++;
        throw new ApplicationException(Constants.ERROR_CODES.DATA_ERROR);
    } finally {
        LOG.debug("messages sent/received/processed/errors: " + sentMessages + "/" + receivedMessages + "/"
                + processedMessages + "/" + errors);
        // updateStats();
    }
    LOG.debug("getRelatedGenes request processing completed");
    return ret;
}

From source file:org.genemania.connector.JmsEngineConnector.java

public UploadNetworkWebResponseDto uploadNetwork(final UploadNetworkWebRequestDto dto)
        throws ApplicationException {
    final String uncid = String.valueOf(System.currentTimeMillis());
    UploadNetworkWebResponseDto ret = new UploadNetworkWebResponseDto();
    jmsTemplate.send(requestQueue, new MessageCreator() {
        public TextMessage createMessage(Session session) throws JMSException {
            LOG.debug("sending UploadnetworkMessage request to " + requestQueue.getQueueName());
            UploadNetworkRequestMessage request = BrokerUtils.dto2msg(dto);
            TextMessage ret = session.createTextMessage(request.toXml());
            ret.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
            ret.setJMSType(MessageType.TEXT2NETWORK.getCode());
            replyQueue = session.createTemporaryQueue();
            ret.setJMSReplyTo(replyQueue);
            ret.setJMSCorrelationID(uncid);
            LOG.debug("uploadNetwork waiting for reply on " + replyQueue.getQueueName());
            sentMessages++;//from   w  ww.j a  v a 2  s  . c  o  m
            return ret;
        }
    });
    Message response;
    try {
        response = jmsTemplate.receive(replyQueue);
        receivedMessages++;
        if (response.getJMSCorrelationID().equals(uncid)) {
            LOG.debug("uploadNetwork reply received");

            if (response != null) {
                String responseBody = ((TextMessage) response).getText();
                if (StringUtils.isNotEmpty(responseBody)) {
                    UploadNetworkResponseMessage responseMessage = UploadNetworkResponseMessage
                            .fromXml(responseBody);
                    if (responseMessage.getErrorCode() == 0) {
                        ret = BrokerUtils.msg2dto(responseMessage);
                    } else {
                        throw new ApplicationException(responseMessage.getErrorMessage(),
                                responseMessage.getErrorCode());
                    }
                } else {
                    LOG.error("uploadNetwork empty response body");
                }
            } else {
                LOG.error("uploadNetwork JMS response is null");
            }
        }
        processedMessages++;
    } catch (JMSException e) {
        errors++;
        throw new ApplicationException(Constants.ERROR_CODES.APPLICATION_ERROR);
    } finally {
        LOG.debug("messages sent/received/processed/appErrors/errors: " + sentMessages + "/" + receivedMessages
                + "/" + processedMessages + "/" + appErrors + "/" + errors);
        // updateStats();
    }
    LOG.debug("uploadNetwork request processing completed");
    return ret;
}

From source file:org.geoserver.wfs.notification.JMSEventHelper.java

private boolean fireNotification(String byteString, JMSInfo info) {
    Session session = null;
    for (int i = 0; i < 5 && !info.closed; ++i) {
        session = info.getSession();/*from   www  .  j  a  va2 s.c o  m*/

        if (session == null) {
            continue;
        }

        try {
            MessageProducer producer = session.createProducer(null);
            Message message = session.createTextMessage(byteString);
            for (Destination d : info.destinations) {
                producer.send(d, message);
            }
            return true;
        } catch (Exception e) {
            recordFailure(e);
            info.invalidateSession(session);
            session = null; // Don't try to return the session
            continue;
        } finally {
            try {
                if (session != null) {
                    info.returnSession(session);
                }
            } catch (Exception e) {
                // ignore
            }
        }
    }

    // Ran out of retries

    return false;
}

From source file:org.hoteia.qalingo.core.jms.cacheflush.producer.CacheFlushMessageProducer.java

/**
 * Generates JMS messages//from  w w  w . ja va  2s .  c o  m
 * 
 */
public void generateAndSendMessages(final CacheFlushMessageJms cacheFlushMessageJms) {
    try {
        final String valueJMSMessage = xmlMapper.getXmlMapper().writeValueAsString(cacheFlushMessageJms);

        if (StringUtils.isNotEmpty(valueJMSMessage)) {
            jmsTemplate.send(new MessageCreator() {
                public Message createMessage(Session session) throws JMSException {
                    TextMessage message = session.createTextMessage(valueJMSMessage);
                    if (logger.isDebugEnabled()) {
                        logger.info("Sending JMS message: " + valueJMSMessage);
                    }
                    return message;
                }
            });
        } else {
            logger.warn("Cache Flush Message Jms Message is empty");
        }

    } catch (JmsException e) {
        logger.error("Exception during create/send message process");
    } catch (JsonProcessingException e) {
        logger.error("Exception during build message process");
    }
}

From source file:org.hoteia.qalingo.core.jms.cms.producer.CmsMessageProducer.java

/**
 * Generates JMS messages//w  w w.  j  a va 2s.  c om
 * 
 */
public void generateAndSendMessages(final String valueJMSMessage) {
    try {
        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(valueJMSMessage);
                if (logger.isDebugEnabled()) {
                    logger.info("Sending JMS message: " + valueJMSMessage);
                }
                return message;
            }
        });
    } catch (Exception e) {
        logger.error("Exception during create/send message process");
    }
}

From source file:org.hoteia.qalingo.core.jms.document.producer.DocumentMessageProducer.java

/**
 * Generates JMS messages//from   w  w w . j a v a2  s.  c  o  m
 * 
 */
public void generateAndSendMessages(final GenerationDocumentMessageJms documentMessageJms) {
    try {
        final String valueJMSMessage = xmlMapper.getXmlMapper().writeValueAsString(documentMessageJms);

        if (StringUtils.isNotEmpty(valueJMSMessage)) {
            jmsTemplate.send(new MessageCreator() {
                public Message createMessage(Session session) throws JMSException {
                    TextMessage message = session.createTextMessage(valueJMSMessage);
                    if (logger.isDebugEnabled()) {
                        logger.info("Sending JMS message: " + valueJMSMessage);
                    }
                    return message;
                }
            });
        } else {
            logger.warn("Doucument Message Jms Message is empty");
        }

    } catch (JmsException e) {
        logger.error("Exception during create/send message process");
    } catch (JsonProcessingException e) {
        logger.error("Exception during build message process");
    }
}

From source file:org.hoteia.qalingo.core.jms.entitycheck.producer.EntityCheckMessageProducer.java

/**
 * Generates JMS messages//from  w  w w.  j av  a2s . c  o  m
 * 
 * @throws UnsupportedEncodingException
 */
public void generateAndSendMessages(final EntityCheckMessageJms messageJms)
        throws JMSException, UnsupportedEncodingException {
    try {
        final String valueJMSMessage = xmlMapper.getXmlMapper().writeValueAsString(messageJms);

        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(valueJMSMessage);
                if (logger.isDebugEnabled()) {
                    logger.info("Sending JMS message: " + valueJMSMessage);
                }
                return message;
            }
        });
    } catch (Exception e) {
        logger.error("Exception during create/send message process");
    }
}

From source file:org.hoteia.qalingo.core.jms.geoloc.producer.AddressGeolocMessageProducer.java

/**
 * Generates JMS messages/*from   w  ww .  ja va 2s  .  c  o m*/
 * 
 * @throws UnsupportedEncodingException
 */
public void generateAndSendMessages(final AddressGeolocMessageJms geolocMessageJms)
        throws JMSException, UnsupportedEncodingException {
    try {
        final String valueJMSMessage = xmlMapper.getXmlMapper().writeValueAsString(geolocMessageJms);

        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(valueJMSMessage);
                if (logger.isDebugEnabled()) {
                    logger.info("Sending JMS message: " + valueJMSMessage);
                }
                return message;
            }
        });
    } catch (Exception e) {
        logger.error("Exception during create/send message process");
    }
}

From source file:org.hoteia.qalingo.core.jms.indexing.producer.IndexingObjectMessageProducer.java

/**
 * Generates JMS messages//from  w w w  .  j a  v  a2 s  . c  o  m
 * 
 * @throws UnsupportedEncodingException
 */
public void generateAndSendMessages(final IndexingObjectMessageJms indexingObjectMessageJms)
        throws JMSException, UnsupportedEncodingException {
    try {
        final String valueJMSMessage = xmlMapper.getXmlMapper().writeValueAsString(indexingObjectMessageJms);

        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(valueJMSMessage);
                if (logger.isDebugEnabled()) {
                    logger.info("Sending JMS message: " + valueJMSMessage);
                }
                return message;
            }
        });
    } catch (Exception e) {
        logger.error("Exception during create/send message process");
    }
}

From source file:org.hoteia.qalingo.core.jms.notification.producer.EmailNotificationMessageProducer.java

/**
 * Generates JMS messages//from w  ww .  ja va  2 s  .co m
 * 
 * @throws UnsupportedEncodingException
 */
public void generateAndSendMessages(final EmailNotificationMessageJms emailnotificationMessageJms)
        throws JMSException, UnsupportedEncodingException {
    try {
        final String valueJMSMessage = xmlMapper.getXmlMapper().writeValueAsString(emailnotificationMessageJms);

        jmsTemplate.send(new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(valueJMSMessage);
                if (logger.isDebugEnabled()) {
                    logger.info("Sending JMS message: " + valueJMSMessage);
                }
                return message;
            }
        });
    } catch (Exception e) {
        logger.error("Exception during create/send message process");
    }
}