List of usage examples for javax.jms Session AUTO_ACKNOWLEDGE
int AUTO_ACKNOWLEDGE
To view the source code for javax.jms Session AUTO_ACKNOWLEDGE.
Click Source Link
From source file:org.apache.falcon.regression.core.supportClasses.JmsMessageConsumer.java
@Override public void run() { try {/* w ww . ja v a 2 s. c om*/ // Getting JMS connection from the server Connection connection = new ActiveMQConnectionFactory(brokerURL).createConnection(); connection.start(); // Creating session for sending messages Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createTopic(topicName); MessageConsumer consumer = session.createConsumer(destination); try { LOGGER.info("Starting to receive messages."); int count = 0; for (; count < MAX_MESSAGE_COUNT; ++count) { Message message = consumer.receive(); //blocking call if (message == null) { LOGGER.info("Received empty message, count = " + count); } else { LOGGER.info("Received message, id = " + message.getJMSMessageID()); receivedMessages.add((MapMessage) message); } } if (count >= MAX_MESSAGE_COUNT) { LOGGER.warn("Not reading more messages, already read " + count + " messages."); } } finally { LOGGER.info("Stopping to receive messages."); connection.close(); } } catch (Exception e) { LOGGER.info("caught exception: " + ExceptionUtils.getStackTrace(e)); } }
From source file:org.wso2.carbon.esb.scenario.test.common.jms.ActiveMQJMSClient.java
/** * Function to retrieve message from specified message queue * * @param queueName Name of the queue//from ww w . j av a 2 s. c om * @param timeout Timeout value (in milliseconds) * @return Retrieved message from the queue * @throws JMSException if error occurred */ public Message consumeMessageFromQueue(String queueName, long timeout) throws JMSException { Connection connection = null; Session session = null; MessageConsumer consumer = null; try { // Create a ConnectionFactory ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl); // Create a Connection connection = connectionFactory.createConnection(); connection.start(); connection.setExceptionListener(this); // Create a Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create the destination (Topic or Queue) Destination destination = session.createQueue(queueName); // Create a MessageConsumer from the Session to the Topic or Queue consumer = session.createConsumer(destination); // Wait for a message return consumer.receive(timeout); } finally { if (consumer != null) { consumer.close(); } if (session != null) { session.close(); } if (connection != null) { connection.close(); } } }
From source file:com.icesoft.net.messaging.jms.JMSPublisherConnection.java
public JMSPublisherConnection(final Topic topic, final JMSAdapter jmsAdapter) throws IllegalArgumentException { super(topic, jmsAdapter, Session.AUTO_ACKNOWLEDGE); }
From source file:TopicPublisher.java
private void run() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url); connection = factory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); topic = session.createTopic("topictest.messages"); control = session.createTopic("topictest.control"); publisher = session.createProducer(topic); publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT); payload = new byte[size]; for (int i = 0; i < size; i++) { payload[i] = (byte) DATA[i % DATA.length]; }// ww w . j a va2 s. c o m session.createConsumer(control).setMessageListener(this); connection.start(); long[] times = new long[batch]; for (int i = 0; i < batch; i++) { if (i > 0) { Thread.sleep(delay * 1000); } times[i] = batch(messages); System.out.println("Batch " + (i + 1) + " of " + batch + " completed in " + times[i] + " ms."); } long min = min(times); long max = max(times); System.out.println("min: " + min + ", max: " + max + " avg: " + avg(times, min, max)); // request shutdown publisher.send(session.createTextMessage("SHUTDOWN")); connection.stop(); connection.close(); }
From source file:net.blogracy.services.StoreService.java
public StoreService(Connection connection, PluginInterface plugin) { this.plugin = plugin; try {//from ww w . ja v a 2s .c o m session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(null); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); queue = session.createQueue("store"); consumer = session.createConsumer(queue); consumer.setMessageListener(this); } catch (JMSException e) { Logger.error("JMS error: creating store service"); } }
From source file:net.blogracy.services.SeedService.java
public SeedService(Connection connection, PluginInterface plugin) { this.plugin = plugin; try {/*from w ww .j a v a 2 s .c o m*/ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(null); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); queue = session.createQueue("seed"); consumer = session.createConsumer(queue); consumer.setMessageListener(this); } catch (JMSException e) { Logger.error("JMS error: creating seed service"); } }
From source file:org.apache.activemq.JmsConnectionStartStopTest.java
/** * Tests if the consumer receives the messages that were sent before the * connection was started.//w w w. j a v a2 s.c o m * * @throws JMSException */ public void testStoppedConsumerHoldsMessagesTillStarted() throws JMSException { Session startedSession = startedConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); Session stoppedSession = stoppedConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Setup the consumers. Topic topic = startedSession.createTopic("test"); MessageConsumer startedConsumer = startedSession.createConsumer(topic); MessageConsumer stoppedConsumer = stoppedSession.createConsumer(topic); // Send the message. MessageProducer producer = startedSession.createProducer(topic); TextMessage message = startedSession.createTextMessage("Hello"); producer.send(message); // Test the assertions. Message m = startedConsumer.receive(1000); assertNotNull(m); m = stoppedConsumer.receive(1000); assertNull(m); stoppedConnection.start(); m = stoppedConsumer.receive(5000); assertNotNull(m); startedSession.close(); stoppedSession.close(); }
From source file:org.fusesource.stompjms.JmsTestSupport.java
protected void sendMessages(Connection connection, Destination destination, int count) throws JMSException { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); sendMessages(session, destination, count); session.close();// w w w . j ava 2s .com }
From source file:org.apache.jmeter.protocol.jms.sampler.Receiver.java
/** * Constructor/*from www . j a v a2 s . c om*/ * @param factory * @param receiveQueue Receive Queue * @param principal Username * @param credentials Password * @param useResMsgIdAsCorrelId * @param jmsSelector JMS Selector * @throws JMSException */ private Receiver(ConnectionFactory factory, Destination receiveQueue, String principal, String credentials, boolean useResMsgIdAsCorrelId, String jmsSelector) throws JMSException { if (null != principal && null != credentials) { log.info("creating receiver WITH authorisation credentials. UseResMsgId=" + useResMsgIdAsCorrelId); conn = factory.createConnection(principal, credentials); } else { log.info("creating receiver without authorisation credentials. UseResMsgId=" + useResMsgIdAsCorrelId); conn = factory.createConnection(); } session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); if (log.isDebugEnabled()) { log.debug("Receiver - ctor. Creating consumer with JMS Selector:" + jmsSelector); } if (StringUtils.isEmpty(jmsSelector)) { consumer = session.createConsumer(receiveQueue); } else { consumer = session.createConsumer(receiveQueue, jmsSelector); } this.useResMsgIdAsCorrelId = useResMsgIdAsCorrelId; log.debug("Receiver - ctor. Starting connection now"); conn.start(); log.info("Receiver - ctor. Connection to messaging system established"); }
From source file:org.apache.servicemix.jbi.cluster.requestor.AbstractPollingRequestorPool.java
public void setTransacted(Transacted transacted) { this.transacted = transacted; switch (transacted) { case None:/* w w w . j a v a2 s. c o m*/ setSessionTransacted(false); setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE); break; case ClientAck: setSessionTransacted(false); setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE); break; case Jms: case Xa: setSessionTransacted(true); break; } }