List of usage examples for javax.jms Session createTextMessage
TextMessage createTextMessage(String text) throws JMSException;
From source file:pl.baczkowicz.mqspy.connectivity.jms.JmsConnection.java
@Override public void publish(final String publicationTopic, final String data) { jmsTemplate.send(publicationTopic, new MessageCreator() { @Override/* w ww . j a va2 s . c o m*/ public Message createMessage(final Session session) throws JMSException { return session.createTextMessage(data); } }); }
From source file:com.provenance.cloudprovenance.connector.policy.PolicyEventConsumer.java
/** Method called when a new message arrives */ public void onMessage(final Message message) { final String outcome; logger.info("Received policy request message = " + counter++); // Check if the message is a text message if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; String policyRequest = null; try {/*from w ww . j a va2s . c o m*/ policyRequest = textMessage.getText(); logger.info("Sending poicy request: " + policyRequest + " ....."); String response = poEnforcement.policyRequest(serviceID, policyRequest); logger.info("Response received for policy request: " + response); String responsURI = resExtraction.getResponseURI(response); logger.debug("Sucessfully extracted response message URI from the policy execution: " + responsURI); outcome = poEnforcement.policyResponse(serviceID, new URL(responsURI)); logger.info("Successfully retrieved a policy response: " + outcome); logger.info( "Sending the retrieved response to a Queue for a client to read: " + outcome + " ......"); jmsTemplate.send(responsePolicyQueueName, new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(outcome); return message; } }); logger.info("Successfully sent the response via the JMS queue to a client"); } catch (JMSException e) { e.printStackTrace(); } catch (XPathExpressionException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { logger.warn("Message received, but unable to process : " + message + " ... !"); } }
From source file:samples.jms.sessioncallback.SessionCallbackExampleTests.java
@Test public void testSessionCallback() { jmsTemplate.execute(new SessionCallback<Object>() { public Object doInJms(Session session) throws JMSException { Queue queue = session.createQueue("someQueue"); MessageProducer producer = session.createProducer(queue); Message message = session.createTextMessage("Hello Queue!"); producer.send(message);/*from ww w .ja va 2 s . c o m*/ return null; } }); }
From source file:org.logicblaze.lingo.jms.marshall.XStreamMarshaller.java
public Message createResponseMessage(Session session, RemoteInvocationResult result, Message requestMessage) throws JMSException { String xml = toXML(result);/* ww w . j av a 2 s .c o m*/ TextMessage message = session.createTextMessage(xml); appendMessageHeaders(message, session, result); return message; }
From source file:org.apache.servicemix.jms.JMSComponentTest.java
public void testConsumerInOut() throws Exception { // JMS Component JmsComponent component = new JmsComponent(); container.activateComponent(component, "JMSComponent"); // Add an echo component EchoComponent echo = new EchoComponent(); ActivationSpec asEcho = new ActivationSpec("receiver", echo); asEcho.setService(new QName("http://jms.servicemix.org/Test", "Echo")); container.activateComponent(asEcho); // Deploy Consumer SU URL url = getClass().getClassLoader().getResource("consumer/jms.wsdl"); File path = new File(new URI(url.toString())); path = path.getParentFile();// ww w . j a v a 2 s . c o m component.getServiceUnitManager().deploy("consumer", path.getAbsolutePath()); component.getServiceUnitManager().init("consumer", path.getAbsolutePath()); component.getServiceUnitManager().start("consumer"); // Send test message jmsTemplate.setDefaultDestinationName("queue/A"); jmsTemplate.afterPropertiesSet(); jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { Message m = session.createTextMessage("<hello>world</hello>"); m.setJMSReplyTo(session.createQueue("queue/B")); return m; } }); // Receive echo message TextMessage reply = (TextMessage) jmsTemplate.receive("queue/B"); assertNotNull(reply); logger.info(reply.getText()); }
From source file:com.provenance.cloudprovenance.eventhandler.service.EventProducer.java
public String sendToQueue(final String eventTypeDestination, final String resourceElements) { String policyResponseMsg = null; final String IGNORE_RECEIVE_QUEUE = "traceabilityQueue"; jmsTemplate.send(eventTypeDestination, new MessageCreator() { public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(resourceElements); return message; }//from ww w .j av a 2 s . c om }); logger.info("Message sent: " + resourceElements); if (!(eventTypeDestination.equals(IGNORE_RECEIVE_QUEUE))) { logger.info("waiting for response message from queue: " + responsePolicyQueueName); jmsTemplate.setReceiveTimeout(5000); Message message = jmsTemplate.receive(responsePolicyQueueName); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; try { policyResponseMsg = textMessage.getText(); logger.info("Message received: " + policyResponseMsg); return policyResponseMsg; } catch (JMSException e) { e.printStackTrace(); } } // it is a traceability event, i.e asynchronized } else if (eventTypeDestination.equals(IGNORE_RECEIVE_QUEUE)) { // need to return the policy id // if a response is needed from the store record (i.e synchronized) if (traceabilityStoreStorageAck) { // wait for a response; logger.info( "waiting for a traceability response message from queue: " + responseTraceabilityQueueName); jmsTemplate.setReceiveTimeout(5000); Message message = jmsTemplate.receive(responseTraceabilityQueueName); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; try { String traceabilityResponseMsg = textMessage.getText(); logger.info("Message received, Id : " + traceabilityResponseMsg); return traceabilityResponseMsg; } catch (JMSException e) { e.printStackTrace(); } } } return "traceability stored successfully"; } // did not recognise the message return null; }
From source file:org.ala.jms.JmsMessageProducer.java
@Test public void generateInvalidMessage() throws JMSException { template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { String json = ""; TextMessage message = session.createTextMessage(json); message.setStringProperty(JmsMessageListener.MESSAGE_METHOD, JmsMessageListener.Method.CREATE.toString()); logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD) + " == " + json); return message; }/* w w w. ja v a2 s. c om*/ }); }
From source file:sk.seges.test.jms.multiple.QueueSendReceiveTest.java
@Test public void testSend() throws Exception { Connection connection = testConnectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(testQueueA); producer.setDeliveryMode(DeliveryMode.PERSISTENT); TextMessage message = session.createTextMessage("test text"); producer.send(message);//from w w w . j ava 2 s.c o m connection.close(); }
From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java
private void sendTestMessage(final Connection directConnection) throws Exception { final Session session = directConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageProducer producer = session.createProducer(session.createQueue(QNAME)); producer.send(session.createTextMessage(uniqueId)); session.close();/* w w w. j ava 2 s . c om*/ }
From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueSendReceiveTest.java
@Test public void testSend() throws Exception { Connection connection = activeMQConnectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(activeMQTestQueueA); producer.setDeliveryMode(DeliveryMode.PERSISTENT); TextMessage message = session.createTextMessage("test text"); producer.send(message);/*from w ww . j a v a2 s. c om*/ connection.close(); }