Example usage for javax.jms Session createMapMessage

List of usage examples for javax.jms Session createMapMessage

Introduction

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

Prototype


MapMessage createMapMessage() throws JMSException;

Source Link

Document

Creates a MapMessage object.

Usage

From source file:com.apress.prospringintegration.transform.IntegrationTransformer.java

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:integration-transformer.xml");

    JmsTemplate jmsTemplate = context.getBean("jmsTemplate", JmsTemplate.class);

    jmsTemplate.send(new MessageCreator() {

        @Override//from   ww  w  .  ja  v  a 2s. c  o  m
        public javax.jms.Message createMessage(Session session) throws JMSException {
            MapMessage message = session.createMapMessage();
            message.setString("firstName", "John");
            message.setString("lastName", "Smith");
            message.setString("address", "100 State Street");
            message.setString("city", "Los Angeles");
            message.setString("state", "CA");
            message.setString("zip", "90064");
            System.out.println("Sending message: " + message);
            return message;
        }
    });

    PollableChannel output = (PollableChannel) context.getBean("output");
    Message<?> reply = output.receive();
    System.out.println("received: " + reply.getPayload());
}

From source file:service.emailer.Emailer.java

/**
 * Send email with parameters to emailQueue
 * @param area/*from   ww w. j  a va 2s.c o m*/
 * @param email
 */
public static void sendEmail(String area, List<String> email) {
    try {
        //JMS QUEUE SEND
        final ConnectionFactory connectionFactory = lookup(ConnectionFactory.class, JNDI_CONNECTION_FACTORY);
        final Queue queue = lookup(Queue.class, JNDI_QUEUE);

        Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        MapMessage message = session.createMapMessage();
        message.setString("type", "warnFile");
        message.setString("area", area);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(email);
        message.setString("emailReceivers", json);
        producer.send(message);
    } catch (JMSException ex) {
        Logger.getLogger(Emailer.class.getName()).log(Level.SEVERE, null, ex);
    } catch (JsonProcessingException ex) {
        Logger.getLogger(Emailer.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.mirth.connect.connectors.jms.JmsMessageUtils.java

public static Message getMessageForObject(Object object, Session session) throws JMSException {
    if (object instanceof Message) {
        return (Message) object;
    } else if (object instanceof String) {
        TextMessage text = session.createTextMessage((String) object);
        return text;
    } else if (object instanceof Map) {
        MapMessage map = session.createMapMessage();
        Map.Entry entry = null;//from  w ww .j a  v a 2 s  .c  o  m
        Map temp = (Map) object;

        for (Iterator i = temp.entrySet().iterator(); i.hasNext();) {
            entry = (Map.Entry) i.next();
            map.setObject(entry.getKey().toString(), entry.getValue());
        }

        return map;
    } else if (object instanceof InputStream) {
        StreamMessage stream = session.createStreamMessage();
        InputStream temp = (InputStream) object;

        byte[] buffer = new byte[1024 * 4];
        int len = 0;
        try {
            while ((len = temp.read(buffer)) != -1) {
                stream.writeBytes(buffer, 0, len);
            }
        } catch (IOException e) {
            throw new JMSException("Failed to read input stream to create a stream message: " + e);
        }

        return stream;
    } else if (object instanceof byte[]) {
        BytesMessage bytes = session.createBytesMessage();
        byte[] buf = (byte[]) object;
        for (int i = 0; i < buf.length; i++) {
            bytes.writeByte(buf[i]);
        }

        return bytes;
    } else if (object instanceof Serializable) {
        ObjectMessage oMsg = session.createObjectMessage();
        oMsg.setObject((Serializable) object);
        return oMsg;
    } else {
        throw new JMSException(
                "Source was not a supported type, data must be Serializable, String, byte[], Map or InputStream");
    }
}

From source file:com.santika.hendi.activeMQ.MessageProducerBean.java

public void sendMessage(final MessageObject messageObj) {
    jmsTemplate.send(destination, new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            MapMessage message = session.createMapMessage();
            message.setString("mailId", messageObj.getMailId());
            message.setString("message", messageObj.getMessage());
            return message;
        }//from   ww  w  .j a  v a  2s .c  o  m
    }); //send method close here
}

From source file:edu.psu.citeseerx.myciteseer.messaging.SubmissionSender.java

public Message createMessage(Session session) throws JMSException {
    MapMessage msg = session.createMapMessage();
    msg.setString("JID", JID);
    msg.setString("URL", URL);
    msg.setString("DESC", DESC);
    return msg;/*from  w  w  w.  j  a v  a  2 s. co  m*/
}

From source file:com.appdynamicspilot.jms.MessageProducer.java

/**
 * Send message to for email to user by given orderid
 *//*  w w w.  j ava  2 s  . c om*/
public void sendMessageWithOrderId(final String orderId, final String emailId) {
    getJmsTemplate().send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            MapMessage msg = session.createMapMessage();
            msg.setString(COMMAND, CMD_MAIL);
            msg.setString(EMAIL_ID, emailId);
            msg.setString(ORDER_ID, orderId);
            msg.setIntProperty("testproperty", 21);
            return msg;
        }
    });
}

From source file:com.xyxy.platform.examples.showcase.demos.jms.advanced.AdvancedNotifyMessageProducer.java

/**
 * jmsTemplatesend/MessageCreator()??Map?Message?.
 *///from   w  w w  .  j a va2 s . c  o  m
private void sendMessage(final User user, Destination destination) {
    jmsTemplate.send(destination, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {

            MapMessage message = session.createMapMessage();
            message.setString("userName", user.getName());
            message.setString("email", user.getEmail());

            message.setStringProperty("objectType", "user");

            return message;
        }
    });
}

From source file:com.it.j2ee.modules.jms.advanced.AdvancedNotifyMessageProducer.java

/**
 * jmsTemplatesend/MessageCreator()??Map?Message?.
 *//*from  w  w  w.ja v a  2  s .  co  m*/
private void sendMessage(final User user, Destination destination) {
    jmsTemplate.send(destination, new MessageCreator() {

        public Message createMessage(Session session) throws JMSException {

            MapMessage message = session.createMapMessage();
            message.setString("userName", user.getName());
            message.setString("email", user.getEmail());

            message.setStringProperty("objectType", "user");

            return message;
        }
    });
}

From source file:com.xyxy.platform.examples.showcase.demos.jms.JmsAdvancedTest.java

@Test
public void topicMessageWithWrongType() {
    Threads.sleep(1000);//from w w w  .jav a2  s. c  om
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(AdvancedNotifyMessageListener.class);

    advancedJmsTemplate.send(advancedNotifyTopic, new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {

            MapMessage message = session.createMapMessage();
            message.setStringProperty("objectType", "role");
            return message;
        }
    });

    Threads.sleep(1000);
    assertThat(appender.isEmpty()).isTrue();
}

From source file:com.it.j2ee.jms.JmsAdvancedTest.java

@Test
public void topicMessageWithWrongType() throws InterruptedException {
    Thread.sleep(1000);//  w  ww.java2 s  .  c  o m
    LogbackListAppender appender = new LogbackListAppender();
    appender.addToLogger(AdvancedNotifyMessageListener.class);

    advancedJmsTemplate.send(advancedNotifyTopic, new MessageCreator() {

        public Message createMessage(Session session) throws JMSException {

            MapMessage message = session.createMapMessage();
            message.setStringProperty("objectType", "role");
            return message;
        }
    });

    Thread.sleep(1000);
    assertThat(appender.isEmpty()).isTrue();
}