List of usage examples for javax.jms Session createProducer
MessageProducer createProducer(Destination destination) throws JMSException;
From source file:org.firstopen.singularity.util.JMSUtil.java
public static void deliverMessageToTopic(String host, String topicName, String xml) { log.debug("IntegrationMod.deliverMessageToQueue queueName = " + topicName + " and doc = " + xml); char test = topicName.charAt(0); if (test == '/') topicName = topicName.substring(1); try {/*from ww w . j a v a 2 s . c o m*/ InitialContext context = JNDIUtil.getInitialContext(host); Connection connection = null; Session session = null; MessageProducer publisher = null; ConnectionFactory tcf = (ConnectionFactory) context.lookup("ConnectionFactory"); Topic topic = (Topic) context.lookup(topicName); connection = tcf.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); publisher = session.createProducer(topic); TextMessage message = session.createTextMessage(); log.debug("message value is -> " + xml); message.setText(xml); publisher.send(message); } catch (Exception e) { log.error("unable to send message on topic", e); } finally { } }
From source file:org.apache.activemq.bugs.AMQ7067Test.java
protected static void produce(Connection connection, Queue queue, int messageCount, int messageSize) throws JMSException, IOException, XAException { Session session = connection.createSession(true, Session.SESSION_TRANSACTED); MessageProducer producer = session.createProducer(queue); for (int i = 0; i < messageCount; i++) { TextMessage helloMessage = session.createTextMessage(StringUtils.repeat("a", messageSize)); producer.send(helloMessage);//from w w w .java 2 s.co m session.commit(); } }
From source file:org.apache.axis2.transport.jms.JMSUtils.java
/** * This is a JMS spec independent method to create a MessageProducer. Please be cautious when * making any changes//from w ww . j a va2 s . com * * @param session JMS session * @param destination the Destination * @param isQueue is the Destination a queue? * @param jmsSpec11 should we use JMS 1.1 API ? * @return a MessageProducer to send messages to the given Destination * @throws JMSException on errors, to be handled and logged by the caller */ public static MessageProducer createProducer(Session session, Destination destination, Boolean isQueue, boolean jmsSpec11) throws JMSException { if (jmsSpec11 || isQueue == null) { return session.createProducer(destination); } else { if (isQueue) { return ((QueueSession) session).createSender((Queue) destination); } else { return ((TopicSession) session).createPublisher((Topic) destination); } } }
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;/*from w ww . j av a 2 s .com*/ Session m_session = null; 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: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);/*w w w .j a v a 2s . c o m*/ connection.close(); }
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 ww.ja v a 2 s . com connection.close(); }
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);//ww w . ja v a 2s .co m return null; } }); }
From source file:org.apache.storm.jms.spout.JmsSpoutTest.java
public Message sendMessage(ConnectionFactory connectionFactory, Destination destination) throws JMSException { Session mySess = connectionFactory.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); MessageProducer producer = mySess.createProducer(destination); TextMessage msg = mySess.createTextMessage(); msg.setText("Hello World"); log.debug("Sending Message: " + msg.getText()); producer.send(msg);/*www . j a va 2 s . c o m*/ return msg; }
From source file:biz.fstechnology.micro.common.jms.SyncSessionCallbackImpl.java
protected MessageProducer createProducer(Session session, Topic destTopic) { try {//from w w w . ja va 2 s. co m return session.createProducer(destTopic); } catch (JMSException ex) { throw new RuntimeException(ex); } }
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();/*from w ww.j a v a2 s . c o 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(); }