List of usage examples for javax.jms MessageProducer send
void send(Message message) throws JMSException;
From source file:org.apache.activemq.bugs.AMQ7067Test.java
protected static void createDanglingTransaction(XAResource xaRes, XASession xaSession, Queue queue) throws JMSException, IOException, XAException { MessageProducer producer = xaSession.createProducer(queue); XATransactionId txId = createXATransaction(); xaRes.start(txId, TMNOFLAGS);//from ww w . j a v a 2s . c o m TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("dangler", 10)); producer.send(helloMessage); xaRes.end(txId, TMSUCCESS); xaRes.prepare(txId); System.out.println("****** createDanglingTransaction txId = " + txId); }
From source file:org.wso2.carbon.sample.jmsclient.JMSClientUtil.java
/** * Each message will be divided into groups and create the map message * * @param producer Used for sending messages to a destination * @param session Used to produce the messages to be sent * @param messagesList List of messages to be sent * individual message event data should be in * "attributeName(attributeType):attributeValue" format *//* ww w .jav a2 s. c o m*/ public static void publishMapMessage(MessageProducer producer, Session session, List<String> messagesList) throws IOException, JMSException { String regexPattern = "(.*)\\((.*)\\):(.*)"; Pattern pattern = Pattern.compile(regexPattern); for (String message : messagesList) { MapMessage mapMessage = session.createMapMessage(); for (String line : message.split("\\n")) { if (line != null && !line.equalsIgnoreCase("")) { Matcher matcher = pattern.matcher(line); if (matcher.find()) { mapMessage.setObject(matcher.group(1), parseAttributeValue(matcher.group(2), matcher.group(3))); } } } producer.send(mapMessage); } }
From source file:org.apache.activemq.bugs.AMQ7067Test.java
protected static void produce(XAResource xaRes, XASession xaSession, Queue queue, int messageCount, int messageSize) throws JMSException, IOException, XAException { MessageProducer producer = xaSession.createProducer(queue); for (int i = 0; i < messageCount; i++) { XATransactionId txid = createXATransaction(); xaRes.start(txid, TMNOFLAGS);/* w ww . j ava2s. c o m*/ TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("a", messageSize)); producer.send(helloMessage); xaRes.end(txid, TMSUCCESS); xaRes.commit(txid, true); } }
From source file:org.wso2.carbon.integration.test.client.JMSPublisherClient.java
/** * Each message will be divided into groups and create the map message * * @param producer Used for sending messages to a destination * @param session Used to produce the messages to be sent * @param messagesList List of messages to be send. An individual message event data should be in * "attributeName(attributeType):attributeValue" format * */// w w w . j a v a 2 s. c om public static void publishMapMessages(MessageProducer producer, Session session, List<String> messagesList) throws JMSException { String regexPattern = "(.*)\\((.*)\\):(.*)"; Pattern pattern = Pattern.compile(regexPattern); for (String message : messagesList) { MapMessage jmsMapMessage = session.createMapMessage(); for (String line : message.split("\\n")) { if (line != null && !line.equalsIgnoreCase("")) { Matcher matcher = pattern.matcher(line); if (matcher.find()) { jmsMapMessage.setObject(matcher.group(1), parseAttributeValue(matcher.group(2), matcher.group(3))); } } } producer.send(jmsMapMessage); } }
From source file:org.firstopen.singularity.util.JMSUtil.java
public static void deliverMessageToQueue(String host, String queueName, String xml) { log.debug("IntegrationMod.deliverMessageToQueue queueName = " + queueName + " and doc = " + xml); MessageProducer m_sender = null; Session m_session = null;//from ww w .ja va 2 s. c o m Connection connection = null; char test = queueName.charAt(0); if (test == '/') queueName = queueName.substring(1); try { InitialContext context = JNDIUtil.getInitialContext(host); ConnectionFactory qcf = (ConnectionFactory) context.lookup("ConnectionFactory"); Queue queue = (Queue) context.lookup("queue/" + queueName); connection = qcf.createConnection(); m_session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); m_sender = m_session.createProducer(queue); TextMessage message = m_session.createTextMessage(); log.debug("message value is -> " + xml); message.setText(xml); m_sender.send(message); } catch (Exception e) { log.error("IntegrationMod.deliverMessageToQueue() Exception = ", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { log.error("unable ot close JMS Connection", e); } } } }
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 . jav a2 s . com*/ }
From source file:example.transaction.Client.java
private static void acceptInputFromUser(Session senderSession, MessageProducer sender) throws JMSException { System.out.println("Type a message. Type COMMIT to send to receiver, type ROLLBACK to cancel"); Scanner inputReader = new Scanner(System.in); while (true) { String line = inputReader.nextLine(); if (line == null) { System.out.println("Done!"); break; } else if (line.length() > 0) { if (line.trim().equals("ROLLBACK")) { System.out.println("Rolling back..."); senderSession.rollback(); System.out.println("Messages have been rolledback"); } else if (line.trim().equals("COMMIT")) { System.out.println("Committing... "); senderSession.commit();/*from ww w . ja va 2 s . co m*/ System.out.println("Messages should have been sent"); } else { TextMessage message = senderSession.createTextMessage(); message.setText(line); System.out.println("Batching up:'" + message.getText() + "'"); sender.send(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); return null; }/*from w w w. j av a 2 s .c o m*/ }); }
From source file:unic.mentoring.jms.ctrl.MessageCtrl.java
protected void sendMessage(String message, String topicName) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(); Connection connection = connectionFactory.createConnection(); connection.start();/* w w w . j a v a 2 s.co m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(topicName); MessageProducer producer = session.createProducer(topic); TextMessage jmsMessage = session.createTextMessage(); jmsMessage.setText(message); producer.send(jmsMessage); connection.close(); }
From source file:org.jbpm.jms.JmsConnectorService.java
final void sendMessage(Job job) throws JMSException { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try {// w ww. ja v a 2 s . c o m Message message = session.createMessage(); populateMessage(message, job); MessageProducer messageProducer = session.createProducer(serviceFactory.getDestination()); messageProducer.send(message); } finally { // there is no need to close the producers of a closed session session.close(); } }