List of usage examples for javax.jms Session createObjectMessage
ObjectMessage createObjectMessage(Serializable object) throws JMSException;
From source file:org.dawnsci.commandserver.mx.example.ActiveMQProducer.java
public static void main(String[] args) throws Exception { QueueConnectionFactory connectionFactory = ConnectionFactoryFacade .createConnectionFactory("tcp://ws097.diamond.ac.uk:61616"); Connection send = connectionFactory.createConnection(); Session session = send.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("testQ"); final MessageProducer producer = session.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); Message message = session.createTextMessage("Hello World"); producer.send(message);//w w w . j a v a 2 s .com message = session.createTextMessage("...and another message"); producer.send(message); message = session.createObjectMessage(new TestObjectBean("this could be", "anything")); producer.send(message); // Test JSON SweepBean col = new SweepBean("fred", "d0000000001", 0, 100); ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(col); message = session.createTextMessage(jsonString); producer.send(message); producer.close(); session.close(); send.close(); // Now we peak at the queue // If the consumer is not going, the messages should still be there if (REQUIRE_PEAK) { QueueConnection qCon = connectionFactory.createQueueConnection(); QueueSession qSes = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queue = qSes.createQueue("testQ"); qCon.start(); QueueBrowser qb = qSes.createBrowser(queue); Enumeration e = qb.getEnumeration(); if (e.hasMoreElements()) System.out.println("Peak at queue:"); while (e.hasMoreElements()) { Message m = (Message) e.nextElement(); if (m == null) continue; if (m instanceof TextMessage) { TextMessage t = (TextMessage) m; System.out.println(t.getText()); } else if (m instanceof ObjectMessage) { ObjectMessage o = (ObjectMessage) m; System.out.println(o.getObject()); } } qb.close(); qSes.close(); qCon.close(); } }
From source file:org.carewebframework.jms.JMSUtil.java
/** * Creates an ObjectMessage from a given session and sets properties of the message (JMSType, * {@value #EVENT_SENDER_PROPERTY}, {@value #EVENT_RECIPIENTS_PROPERTY}. * /*from w w w . ja v a2 s .com*/ * @param session The session for which to create the message. * @param jmsType Message's JMSType. * @param messageData Message data. * @param sender Sender client ID. * @param recipients Comma-delimited list of recipient client IDs * @return MessageThe newly created message. * @throws JMSException if error thrown from creation of object message */ public static Message createObjectMessage(final Session session, final String jmsType, final Serializable messageData, final String sender, final String recipients) throws JMSException { return decorateMessage(session.createObjectMessage(messageData), jmsType, sender, recipients); }
From source file:airport.services.dispatcher.GeneratorFlightJMS.java
public void sendFlight(Flight flight) { jmsTemplate.send(topic, (Session sn) -> sn.createObjectMessage(flight)); if (LOG.isInfoEnabled()) { LOG.info("send message. Flight : " + flight); }/*from ww w. j a v a 2s.c o m*/ }
From source file:Component.JMS.jmsSend.java
public void Send(Destination destination, final Salestatics message) { jmsTemplate.send(destination, new MessageCreator() { @Override//from ww w.ja va 2 s . c o m public Message createMessage(Session session) throws JMSException { return session.createObjectMessage(message); } }); }
From source file:com.rabbitmq.jms.sample.StockQuoter.java
@Scheduled(fixedRate = 5000L) // every 5 seconds public void publishQuote() { // Pick a random stock symbol Collections.shuffle(stocks);//from www . jav a 2 s .c om String symbol = stocks.get(0); // Toss a coin and decide if the price goes... if (RandomUtils.nextBoolean()) { // ...up by a random 0-10% lastPrice.put(symbol, new Double( Math.round(lastPrice.get(symbol) * (1 + RandomUtils.nextInt(10) / 100.0) * 100) / 100)); } else { // ...or down by a similar random amount lastPrice.put(symbol, new Double( Math.round(lastPrice.get(symbol) * (1 - RandomUtils.nextInt(10) / 100.0) * 100) / 100)); } // Log new price locally log.info("Quote..." + symbol + " is now " + lastPrice.get(symbol)); // Coerce a javax.jms.MessageCreator MessageCreator messageCreator = (Session session) -> { return session.createObjectMessage("Quote..." + symbol + " is now " + lastPrice.get(symbol)); }; // And publish to RabbitMQ using Spring's JmsTemplate jmsTemplate.send("rabbit-trader-channel", messageCreator); }
From source file:com.appdynamicspilot.jms.FulfillmentProducer.java
public void sendFulfillment(final FulfillmentOrder order) { getJmsTemplate().send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { ObjectMessage msg = session.createObjectMessage(order); return msg; }/* w w w . jav a 2 s. co m*/ }); }
From source file:org.yestech.notify.service.JmsQueueNotificationProducer.java
@Override public void send(final INotificationJob notificationJob) { jmsTemplate.send(queue, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createObjectMessage(notificationJob); }/* w w w. j a v a 2s . c om*/ }); }
From source file:com.it355.jmsdemo.app.messaging.MessageSender.java
public void sendMessage(final Order order) { jmsTemplate.send(new MessageCreator() { @Override/*from www .ja v a 2 s. c om*/ public Message createMessage(Session session) throws JMSException { ObjectMessage objectMessage = session.createObjectMessage(order); return objectMessage; } }); }
From source file:net.ab0oo.aprs.clients.SimpleMessageProducer.java
public void sendMessage(final Serializable payload) throws JMSException { jmsTemplate.send(new MessageCreator() { @Override/* w ww .j av a 2 s. co m*/ public Message createMessage(Session session) throws JMSException { ObjectMessage message = session.createObjectMessage(payload); message.setIntProperty("messageCount", i); return message; } }); i++; }
From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.OsgpRequestMessageSender.java
public void send(final RequestMessage requestMessage, final String messageType) { LOGGER.info("Sending request message to OSGP."); this.iec61850RequestsJmsTemplate.send(new MessageCreator() { @Override//from w w w.j av a 2 s.c o m public Message createMessage(final Session session) throws JMSException { final ObjectMessage objectMessage = session.createObjectMessage(requestMessage); objectMessage.setJMSType(messageType); objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, requestMessage.getOrganisationIdentification()); objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, requestMessage.getDeviceIdentification()); return objectMessage; } }); }