List of usage examples for javax.jms Session createTextMessage
TextMessage createTextMessage(String text) throws JMSException;
From source file:net.homecredit.book.jms.JmsMessageProducer.java
/** * Generates JMS messages// w w w. jav a 2s . c o m */ @PostConstruct public void generateMessages() throws JMSException { for (int i = 0; i < messageCount; i++) { final int index = i; final String text = "Message number is " + i + "."; template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(text); message.setIntProperty(MESSAGE_COUNT, index); logger.info("Sending message: " + text); return message; } }); } }
From source file:org.esbtools.gateway.resync.service.JmsResyncService.java
private ResyncResponse enqueue(final ResyncRequest resyncRequest) { ResyncResponse resyncResponse = new ResyncResponse(); try {/*from w w w. j a va 2 s . c o m*/ LOGGER.info("Sending message {}", resyncRequest.toXML()); jmsResyncConfiguration.getBroker().send(new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { Message message = session.createTextMessage(resyncRequest.toXML()); return message; } }); resyncResponse.setStatus(ResyncResponse.Status.Success); } catch (RuntimeException e) { LOGGER.error("An error occurred when enqueuing the resync message: {}", resyncRequest, e); throw new ResyncFailedException(resyncRequest); } LOGGER.info("{}", resyncResponse); return resyncResponse; }
From source file:org.usergrid.websocket.SimpleMessageProducer.java
public void sendMessages() throws JMSException { for (int i = 0; i < numberOfMessages; ++i) { final StringBuilder payload = new StringBuilder(); payload.append("Message [").append(i).append("] sent at: ").append(new Date()); final int j = i; jmsTemplate.send(new MessageCreator() { @Override//w w w . j a va 2 s.com public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(payload.toString()); message.setIntProperty("messageCount", j); logger.info("Sending message number [" + j + "]"); return message; } }); } }
From source file:se.inera.intyg.intygstjanst.web.service.impl.StatisticsServiceImplTest.java
@Test public void serviceSendsDocumentAndIdForRevoke() throws JMSException { org.springframework.test.util.ReflectionTestUtils.setField(serviceImpl, "enabled", Boolean.TRUE); ArgumentCaptor<MessageCreator> captor = ArgumentCaptor.forClass(MessageCreator.class); Certificate certificate = mock(Certificate.class); when(certificate.getDocument()).thenReturn("The document"); when(certificate.getId()).thenReturn("The id"); TextMessage message = mock(TextMessage.class); Session session = mock(Session.class); when(session.createTextMessage("The document")).thenReturn(message); serviceImpl.revoked(certificate);/*from www .jav a2s . c o m*/ verify(template, only()).send(captor.capture()); captor.getValue().createMessage(session); verify(message).setStringProperty("action", "revoked"); verify(message).setStringProperty("certificate-id", "The id"); }
From source file:se.inera.intyg.intygstjanst.web.service.impl.StatisticsServiceImplTest.java
@Test public void serviceSendsDocumentAndIdForCreate() throws JMSException { org.springframework.test.util.ReflectionTestUtils.setField(serviceImpl, "enabled", Boolean.TRUE); ArgumentCaptor<MessageCreator> captor = ArgumentCaptor.forClass(MessageCreator.class); Certificate certificate = mock(Certificate.class); when(certificate.getDocument()).thenReturn("The document"); when(certificate.getId()).thenReturn("The id"); TextMessage message = mock(TextMessage.class); Session session = mock(Session.class); when(session.createTextMessage("The document")).thenReturn(message); serviceImpl.created(certificate.getDocument(), certificate.getId(), certificate.getType(), certificate.getCareUnitId()); verify(template, only()).send(captor.capture()); captor.getValue().createMessage(session); verify(message).setStringProperty("action", "created"); verify(message).setStringProperty("certificate-id", "The id"); }
From source file:org.zeromq.jms.TestSpringZmqQueue.java
/** * Send text to default destination./* w w w. j av a2s .co m*/ * @param text the text to send */ public void send(final String text) { this.jmsTemplate.send(new MessageCreator() { @Override public Message createMessage(final Session session) throws JMSException { Message message = session.createTextMessage(text); return message; } }); }
From source file:org.zeromq.jms.TestSpringZmqQueue.java
/** * Send text message to a specified destination. * @param dest the destination/*from www . j a v a 2 s . co m*/ * @param text the test to send */ public void send(final Destination dest, final String text) { this.jmsTemplate.send(dest, new MessageCreator() { @Override public Message createMessage(final Session session) throws JMSException { Message message = session.createTextMessage(text); return message; } }); }
From source file:org.esbtools.gateway.resubmit.service.JmsResubmitService.java
private ResubmitResponse enqueue(final ResubmitRequest resubmitRequest) { ResubmitResponse resubmitResponse = new ResubmitResponse(); try {// w ww . j a v a2 s . c o m LOGGER.info("Sending message {}", resubmitRequest.getPayload()); jmsResubmitConfiguration.getBroker().send(resubmitRequest.getDestination(), new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { Message message = session.createTextMessage(resubmitRequest.getPayload()); if (MapUtils.isNotEmpty(resubmitRequest.getHeaders())) { for (Map.Entry<String, String> header : resubmitRequest.getHeaders().entrySet()) { LOGGER.info("Adding header key={}, value{}", header.getKey(), header.getValue()); message.setStringProperty(header.getKey(), header.getValue()); } } return message; } }); resubmitResponse.setStatus(GatewayResponse.Status.Success); } catch (RuntimeException e) { LOGGER.error("An error occurred when enqueuing the resubmit message: {}", resubmitRequest, e); throw new ResubmitFailedException(resubmitRequest); } LOGGER.info("{}", resubmitResponse); return resubmitResponse; }
From source file:org.camelcookbook.examples.testing.notifybuilder.FixedEndpointsNotifyBuilderSpringTest.java
private void sendMessageBody(final String messageText) { jmsTemplate.send("in", new MessageCreator() { @Override/*from w w w. j ava 2s.com*/ public Message createMessage(Session session) throws JMSException { return session.createTextMessage(messageText); } }); }
From source file:nh.examples.springintegration.order.utils.XmlJmsMessageConverter.java
@Override public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { String xml = _xmlConverter.toXml(object); return session.createTextMessage(xml); }