List of usage examples for javax.jms Session createTextMessage
TextMessage createTextMessage(String text) throws JMSException;
From source file:org.carewebframework.jms.JMSUtil.java
/** * Creates a TextMessage from a given session and sets properties of the message (JMSType, * {@value #EVENT_SENDER_PROPERTY}, {@value #EVENT_RECIPIENTS_PROPERTY}. * //from w w w .j a va 2s .co m * @param session the session for which to create the message * @param jmsType Message's JMSType * @param text text data * @param sender Sender client ID. * @param recipients Comma-delimited list of recipient client IDs * @return Message * @throws JMSException if error thrown from creation of object message */ public static Message createTextMessage(final Session session, final String jmsType, final String text, final String sender, final String recipients) throws JMSException { return decorateMessage(session.createTextMessage(text), jmsType, sender, recipients); }
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;/* www. ja va2 s .co 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:org.dawnsci.commandserver.core.util.JSONUtils.java
/** * Generic way of sending a topic notification * @param connection - does not get closed afterwards nust be started before. * @param message//from ww w. jav a 2s. com * @param topicName * @param uri * @throws Exception */ private static final void sendTopic(Connection connection, Object message, String topicName, URI uri) throws Exception { // JMS messages are sent and received using a Session. We will // create here a non-transactional session object. If you want // to use transactions you should set the first parameter to 'true' Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { Topic topic = session.createTopic(topicName); MessageProducer producer = session.createProducer(topic); final ObjectMapper mapper = new ObjectMapper(); // Here we are sending the message out to the topic TextMessage temp = session.createTextMessage(mapper.writeValueAsString(message)); producer.send(temp, DeliveryMode.NON_PERSISTENT, 1, 5000); } finally { session.close(); } }
From source file:azure.example.app1.services.QueuePublisher.java
public void sendPing() { logger.info("Sending ping"); jmsTemplate.send("myqueue", (Session session) -> session.createTextMessage("ping")); }
From source file:com.abosancic.activemq.service.MessageService.java
private MessageCreator createMessage() { return (Session session) -> session.createTextMessage(gson.toJson(getMessage())); }
From source file:com.shopzilla.spring.messaging.hornetq.config.example.HornetQConfigurationExample.java
@PostConstruct public void start() { final String destination = "exampleQueue"; // this assumes you've configured the relevant queue in your $HORNETQ/**/config folder // send//from ww w.j a v a 2 s .c o m jmsTemplate.send(destination, new MessageCreator() { public Message createMessage(final Session session) throws JMSException { return session .createTextMessage(String.format("Hello, world! @ %s", System.currentTimeMillis() + "")); } }); // receive Message msg = jmsTemplate.receive(destination); System.out.println(ToStringBuilder.reflectionToString(msg)); }
From source file:ragna.wl1036.web.support.MessagingCaller.java
@RequestMapping(value = "/call_test_topic") public @ResponseBody String versionMap() { final MessageCreator messageCreator = new MessageCreator() { @Override/* w w w .java 2 s . c o m*/ public Message createMessage(Session session) throws JMSException { return session.createTextMessage("ping!"); } }; jmsTemplate.send("jms/TestQ", messageCreator); return "sent!"; }
From source file:samples.jms.messagecreator.MessageCreatorExampleTests.java
@Test public void testCreateMessage() { jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createTextMessage("Hello JMS!"); }/*www .j av a2 s . co m*/ }); }
From source file:com.martian.apps.springlab.springactivemq.service.MessageProducer.java
public void sendMessage(final String msg) { LOG.info("Producer sends: " + msg); jmsTemplate.send(destination, new MessageCreator() { @Override/*ww w . jav a 2s. co m*/ public Message createMessage(Session session) throws JMSException { return session.createTextMessage(msg); } }); }
From source file:com.acme.spring.jms.impl.MessageSenderImpl.java
/** * {@inheritDoc}// w w w. ja v a2 s . com */ public void sendMessage(final String message) { jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createTextMessage(message); } }); }