Example usage for javax.jms Session createObjectMessage

List of usage examples for javax.jms Session createObjectMessage

Introduction

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

Prototype


ObjectMessage createObjectMessage() throws JMSException;

Source Link

Document

Creates an ObjectMessage object.

Usage

From source file:org.openadaptor.auxil.connector.jms.DefaultMessageGenerator.java

public Message createMessage(Object messageRecord, Session session) throws JMSException {
    Message msg;//from  ww  w. j av a 2  s  .  c o m
    if (messageRecord instanceof String) {
        TextMessage textMsg = session.createTextMessage();
        textMsg.setText((String) messageRecord);
        msg = textMsg;
    } else if (messageRecord instanceof Serializable) {
        ObjectMessage objectMsg = session.createObjectMessage();
        objectMsg.setObject((Serializable) messageRecord);
        msg = objectMsg;
    } else {
        // We have not needed more message types in practice.
        // If we do need them in future this is where they go.
        throw new RecordFormatException(
                "Undeliverable record type [" + messageRecord.getClass().getName() + "]");
    }
    setMessageProperties(msg);
    return msg;
}

From source file:org.openhie.openempi.notification.impl.NotificationServiceImpl.java

public void fireNotificationEvent(final NotificationEvent event) {
    if (brokerService == null || !brokerInitialized) {
        log.debug("The broker service is not running in fireNotificationEvent.");
        return;/*from   w ww  .j ava 2s  .  c  o  m*/
    }

    if (event == null || event.getEventType() == null) {
        log.warn(
                "Request was made to generate an event but the required attributes were not present in the request.");
        return;
    }
    log.info("Fire notification for event " + event.getEventType().getEventTypeName());

    Topic topic = topicMap.get(event.getEventType().getEventTypeName());
    if (topic == null) {
        log.warn("Request was made to generate an event but the event type is unknown.");
        return;
    }

    try {
        jmsTemplate.send(topic, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                ObjectMessage message = session.createObjectMessage();
                message.setObject(event);
                return message;
            }
        });
    } catch (RuntimeException e) {
        log.warn("Unable to send out a notification event: " + e, e);
    }
}