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.camel.component.jms.JmsComponent.java
/** * Static builder method/*from w w w .j a v a 2 s. co m*/ */ public static JmsComponent jmsComponentAutoAcknowledge(ConnectionFactory connectionFactory) { JmsConfiguration template = new JmsConfiguration(connectionFactory); template.setAcknowledgementMode(Session.AUTO_ACKNOWLEDGE); return jmsComponent(template); }
From source file:org.smartfrog.avalanche.shared.jms.MessageListener.java
public MonitoringEvent receive() throws Exception { MonitoringEvent event = null;//from ww w. j a v a 2s . c o m // TODO : no need to open a new session every time .. fix it QueueSession qs = null; QueueReceiver qr = null; try { qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); qr = qs.createReceiver(queue); // TODO : Fix message timeout log.info("MonitoringEvent.receive() : Checking for new message on Queue"); MapMessage mm = (MapMessage) qr.receive(jmsTimeout); if (mm != null) { log.info("Message received"); event = new MonitoringEventDefaultImpl(); event.setHost(mm.getString(MonitoringEvent.HOST)); event.setInstanceName(mm.getString(MonitoringEvent.INSTANCE_NAME)); event.setModuleId(mm.getString(MonitoringEvent.MODULEID)); event.setModuleState(mm.getString(MonitoringEvent.MODULE_STATE)); event.setMsg(mm.getString(MonitoringEvent.MODULE_STATE)); event.setMessageType(mm.getInt(MonitoringEvent.MESSAGE_TYPE)); log.info("MessageListener.receive() - " + event); } else { log.info("No message found in queue"); } return event; } finally { qr.close(); qs.close(); } }
From source file:org.wso2.carbon.andes.ui.client.QueueBrowserClient.java
/** * Return a lazy-loading iterator (java.util.Enumeration) of the messages of the given queue. * @return java.util.Enumeration/*from w w w . ja v a 2 s . co m*/ */ public Enumeration browseQueue() { Enumeration queueContentsEnu = null; try { InitialContext ctx = new InitialContext(properties); QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME); queueConnection = connFactory.createQueueConnection(); Queue queue = (Queue) ctx.lookup(nameOfQueue); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueBrowser = queueSession.createBrowser(queue); queueConnection.start(); queueContentsEnu = queueBrowser.getEnumeration(); } catch (NamingException e) { log.error("Error browsing queue.", e); } catch (JMSException e) { log.error("Error browsing queue.", e); } return queueContentsEnu; }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Create a JMS Topic using the given connection with the JNDI destination name, and return the * JMS Destination name of the created queue * * @param con the JMS Connection to be used * @param destinationJNDIName the JNDI name of the Topic to be created * @return the JMS Destination name of the created Topic * @throws JMSException on error/*from w ww . j a v a2 s .co m*/ */ public static String createJMSTopic(Connection con, String destinationJNDIName) throws JMSException { try { TopicSession session = ((TopicConnection) con).createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(destinationJNDIName); log.info("JMS Topic with JNDI name : " + destinationJNDIName + " created"); return topic.getTopicName(); } finally { try { con.close(); } catch (JMSException ignore) { } } }
From source file:net.blogracy.controller.DistributedHashTable.java
public DistributedHashTable() { try {/* w w w. j ava 2s . c o m*/ File recordsFile = new File(CACHE_FOLDER + File.separator + "records.json"); if (recordsFile.exists()) { JSONArray recordList = new JSONArray(new JSONTokener(new FileReader(recordsFile))); for (int i = 0; i < recordList.length(); ++i) { JSONObject record = recordList.getJSONObject(i); records.put(record.getString("id"), record); } } connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL); connection = connectionFactory.createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(null); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); lookupQueue = session.createQueue("lookup"); storeQueue = session.createQueue("store"); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.rocketmq.jms.RocketMQConnection.java
@Override public Session createSession(int sessionMode) throws JMSException { if (sessionMode == SESSION_TRANSACTED) { return createSession(true, Session.AUTO_ACKNOWLEDGE); } else {/*from ww w . j a v a2s .c o m*/ return createSession(false, sessionMode); } }
From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java
private void consumeTestMessage() throws Exception { final Connection connection = factory.createConnection(); connection.start();//from w w w.java 2s . com try { final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageConsumer consumer = session.createConsumer(session.createQueue(QNAME)); final Message message = consumer.receive(1000); LOG.info(ObjectUtils.toString(message, "<no message>")); Assert.assertEquals(uniqueId, ((TextMessage) message).getText()); } finally { connection.stop(); connection.close(); } }
From source file:org.wso2.andes.systest.GlobalQueuesTest.java
/** * Test that setting depth has an effect on topics * * Sets the message size for the test/*from w ww . j av a 2 s . co m*/ * Sets the depth to be 9 * the depth * Ensure that sending 10 messages causes the disconnection * * @throws Exception */ public void testTopicConsumerMessageSize() throws Exception { MAX_QUEUE_MESSAGE_COUNT = 10; setConfig("depth", String.valueOf(MESSAGE_SIZE * 9), false); //Start the broker startBroker(); setMessageSize(MESSAGE_SIZE); topicConsumer(Session.AUTO_ACKNOWLEDGE, false); }
From source file:MessageMonitor.java
/** Constructor for MessageMonitor window. */ public MessageMonitor() { loadProperties();//from w w w . j a va 2 s.c o m setTitle(title); // Connect to Message Broker try { javax.jms.ConnectionFactory factory; factory = new ActiveMQConnectionFactory(user, password, url); connection = factory.createConnection(userID, password); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("Cannot connect to Broker"); jmse.printStackTrace(); System.exit(1); } // Subscribe to Topics StringTokenizer topics = new StringTokenizer(subscriptionTopics, ","); while (topics.hasMoreTokens()) { try { String topicName = topics.nextToken(); System.out.println("Subscribing to: " + topicName); new Subscription(session.createTopic(topicName)); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } } // Set up the viewing area. textArea.setEditable(false); scrollPane.setBorder( new CompoundBorder(new EmptyBorder(6, 6, 6, 6), new SoftBevelBorder(BevelBorder.LOWERED))); getContentPane().add(scrollPane, BorderLayout.CENTER); getContentPane().add(clearButton, BorderLayout.SOUTH); clearButton.addActionListener(new OnClear()); // Start the connection so that we can now receive messages. try { connection.start(); } catch (javax.jms.JMSException jmse) { System.err.println("Cannot start connection"); jmse.printStackTrace(); System.exit(1); } }
From source file:org.apache.activemq.usecases.DurableSubscriberWithNetworkDisconnectTest.java
public void testSendOnAReceiveOnBWithTransportDisconnect() throws Exception { bridgeBrokers(SPOKE, HUB);//from ww w .ja v a2 s.co m startAllBrokers(); // Setup connection URI hubURI = brokers.get(HUB).broker.getVmConnectorURI(); URI spokeURI = brokers.get(SPOKE).broker.getVmConnectorURI(); ActiveMQConnectionFactory facHub = new ActiveMQConnectionFactory(hubURI); ActiveMQConnectionFactory facSpoke = new ActiveMQConnectionFactory(spokeURI); Connection conHub = facHub.createConnection(); Connection conSpoke = facSpoke.createConnection(); conHub.setClientID("clientHUB"); conSpoke.setClientID("clientSPOKE"); conHub.start(); conSpoke.start(); Session sesHub = conHub.createSession(false, Session.AUTO_ACKNOWLEDGE); Session sesSpoke = conSpoke.createSession(false, Session.AUTO_ACKNOWLEDGE); ActiveMQTopic topic = new ActiveMQTopic("TEST.FOO"); String consumerName = "consumerName"; // Setup consumers MessageConsumer remoteConsumer = sesSpoke.createDurableSubscriber(topic, consumerName); remoteConsumer.setMessageListener(new MessageListener() { public void onMessage(Message msg) { try { TextMessage textMsg = (TextMessage) msg; receivedMsgs++; LOG.info("Received messages (" + receivedMsgs + "): " + textMsg.getText()); } catch (JMSException e) { e.printStackTrace(); } } }); // allow subscription information to flow back to Spoke sleep(1000); // Setup producer MessageProducer localProducer = sesHub.createProducer(topic); localProducer.setDeliveryMode(DeliveryMode.PERSISTENT); // Send messages for (int i = 0; i < MESSAGE_COUNT; i++) { sleep(50); if (i == 50 || i == 150) { if (simulateStalledNetwork) { socketProxy.pause(); } else { socketProxy.close(); } networkDownTimeStart = System.currentTimeMillis(); } else if (networkDownTimeStart > 0) { // restart after NETWORK_DOWN_TIME seconds sleep(NETWORK_DOWN_TIME); networkDownTimeStart = 0; if (simulateStalledNetwork) { socketProxy.goOn(); } else { socketProxy.reopen(); } } else { // slow message production to allow bridge to recover and limit message duplication sleep(500); } Message test = sesHub.createTextMessage("test-" + i); localProducer.send(test); } LOG.info("waiting for messages to flow"); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return receivedMsgs >= MESSAGE_COUNT; } }); assertTrue("At least message " + MESSAGE_COUNT + " must be received, count=" + receivedMsgs, MESSAGE_COUNT <= receivedMsgs); brokers.get(HUB).broker.deleteAllMessages(); brokers.get(SPOKE).broker.deleteAllMessages(); conHub.close(); conSpoke.close(); }