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.easybatch.tutorials.advanced.jms.JMSUtil.java
public static void initJMSFactory() throws Exception { Properties p = new Properties(); p.load(JMSUtil.class.getResourceAsStream(("/org/easybatch/tutorials/advanced/jms/jndi.properties"))); Context jndiContext = new InitialContext(p); queueConnectionFactory = (QueueConnectionFactory) jndiContext.lookup("QueueConnectionFactory"); queue = (Queue) jndiContext.lookup("q"); QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(); queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queueSender = queueSession.createSender(queue); queueConnection.start();/* w w w .jav a 2 s .c o m*/ }
From source file:com.fusesource.forge.jmstest.tests.AsyncConsumer.java
protected Session getSession() throws Exception { if (session == null) { session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE); }//from w ww. j a v a2 s. c o m return session; }
From source file:Log4jJMSAppenderExample.java
public Log4jJMSAppenderExample() throws Exception { // create a logTopic topic consumer ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection conn = factory.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); conn.start();/* www . j av a2s .com*/ MessageConsumer consumer = sess.createConsumer(sess.createTopic("logTopic")); consumer.setMessageListener(this); // log a message Logger log = Logger.getLogger(Log4jJMSAppenderExample.class); log.info("Test log"); // clean up Thread.sleep(1000); consumer.close(); sess.close(); conn.close(); System.exit(1); }
From source file:org.mule.transport.jms.integration.JmsMessageAwareTransformersMule2685TestCase.java
@Override protected void doSetUp() throws Exception { super.doSetUp(); session = getConnection(false, false).createSession(false, Session.AUTO_ACKNOWLEDGE); }
From source file:com.fusesource.forge.jmstest.tests.simple.SimpleConsumer.java
protected void run() { Connection con = null;/* ww w . j av a 2s .co m*/ Session session = null; final CountDownLatch latch = new CountDownLatch(Integer.MAX_VALUE); try { con = getConnection(); session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination dest = getDestinationProvider().getDestination(session, "queue:TEST"); MessageConsumer consumer = session.createConsumer(dest); consumer.setMessageListener(new MessageListener() { public void onMessage(Message msg) { String grp = null; long nr = 0L; try { grp = msg.getStringProperty("JMSXGroupID"); nr = msg.getLongProperty("MsgNr"); } catch (JMSException jme) { } log().info("Received Message Group=(" + grp + ") MsgNr=" + nr); latch.countDown(); } }); con.start(); latch.await(); con.close(); } catch (Exception e) { } finally { if (con != null) { try { con.close(); } catch (Exception e) { } } } }
From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveFailTest.java
@Test public void testReceive() throws Exception { Connection connection = activeMQConnectionFactory.createConnection(); connection.start();/* w w w. j a v a 2 s . c om*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(activeMQTestQueueA); Message rawMessage = consumer.receive(1000); assertNull(rawMessage); connection.close(); }
From source file:org.apache.stratos.lb.endpoint.subscriber.TopologySubscriber.java
public static void subscribe(String topicName) { Properties initialContextProperties = new Properties(); TopicSubscriber topicSubscriber = null; TopicSession topicSession = null;//from w w w. j av a2 s . c om TopicConnection topicConnection = null; InitialContext initialContext = null; initialContextProperties.put("java.naming.factory.initial", "org.wso2.andes.jndi.PropertiesFileInitialContextFactory"); String mbServerUrl = null; if (ConfigHolder.getInstance().getLbConfig() != null) { mbServerUrl = ConfigHolder.getInstance().getLbConfig().getLoadBalancerConfig().getMbServerUrl(); } String connectionString = "amqp://admin:admin@clientID/carbon?brokerlist='tcp://" + (mbServerUrl == null ? TopologyConstants.DEFAULT_MB_SERVER_URL : mbServerUrl) + "'&reconnect='true'"; initialContextProperties.put("connectionfactory.qpidConnectionfactory", connectionString); try { initialContext = new InitialContext(initialContextProperties); TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) initialContext .lookup("qpidConnectionfactory"); topicConnection = topicConnectionFactory.createTopicConnection(); topicConnection.start(); topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = topicSession.createTopic(topicName); topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(new TopologyListener()); } catch (Exception e) { log.error(e.getMessage(), e); try { if (topicSubscriber != null) { topicSubscriber.close(); } if (topicSession != null) { topicSession.close(); } if (topicConnection != null) { topicConnection.close(); } } catch (JMSException e1) { // ignore } } finally { // start the health checker Thread healthChecker = new Thread(new TopicHealthChecker(topicName, topicSubscriber)); healthChecker.start(); } }
From source file:org.wso2.carbon.sample.jmsclient.JMSClient.java
public static void publishMessages(String topicName, String broker) { try {/* ww w .j a va 2 s .com*/ // filePath = JMSClientUtil.getEventFilePath(sampleNumber, format, topicName, filePath); TopicConnection topicConnection = null; Session session = null; Properties properties = new Properties(); if (broker.equalsIgnoreCase("activemq")) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("activemq.properties")); Context context = new InitialContext(properties); TopicConnectionFactory connFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory"); topicConnection = connFactory.createTopicConnection(); topicConnection.start(); session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } else if (broker.equalsIgnoreCase("mb")) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("mb.properties")); Context context = new InitialContext(properties); TopicConnectionFactory connFactory = (TopicConnectionFactory) context .lookup("qpidConnectionFactory"); topicConnection = connFactory.createTopicConnection(); topicConnection.start(); session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } else if (broker.equalsIgnoreCase("qpid")) { properties.load(ClassLoader.getSystemClassLoader().getResourceAsStream("qpid.properties")); Context context = new InitialContext(properties); TopicConnectionFactory connFactory = (TopicConnectionFactory) context .lookup("qpidConnectionFactory"); topicConnection = connFactory.createTopicConnection(); topicConnection.start(); session = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } else { log.info("Please enter a valid JMS message broker. (ex: activemq, mb, qpid"); } if (session != null) { Topic topic = session.createTopic(topicName); MessageProducer producer = session.createProducer(topic); try { List<Map<String, Object>> messageList = new ArrayList<Map<String, Object>>(); Random random = new Random(); for (int j = 0; j < sessionsPerThread; j++) { for (int i = 0; i < msgsPerSession; i++) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("id", random.nextInt() + ""); map.put("value", random.nextInt()); map.put("content", "sample content"); map.put("client", "jmsQueueClient"); // setting the timestamp later messageList.add(map); } publishMapMessage(producer, session, messageList); } } catch (JMSException e) { log.error("Can not subscribe." + e.getMessage(), e); } catch (IOException e) { log.error("Error when reading the data file." + e.getMessage(), e); } finally { producer.close(); session.close(); topicConnection.stop(); } } } catch (Exception e) { log.error("Error when publishing message" + e.getMessage(), e); } }
From source file:org.sample.TimeController.java
@RequestMapping(method = RequestMethod.GET, value = { "/tick" }) public ModelAndView get() throws Exception { Connection connection = jmsFactory.createConnection(); Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); SecureRandom srandom = new SecureRandom(); String rand = new BigInteger(176, srandom).toString(32); String q = Long.toString(System.currentTimeMillis()) + "-" + rand; Destination destination = jmsSession.createQueue(q); Timer timer = new Timer(); long delay = 1 * 1000; timer.schedule(new TickTask(jmsSession, destination), 0, delay); ModelAndView mav = new ModelAndView("client"); mav.addObject("queue", destination.toString()); return mav;// www .j a v a 2 s. c o m }
From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveTest.java
@Test public void testReceive() throws Exception { Connection connection = activeMQConnectionFactory.createConnection(); connection.start();//from www. j a v a 2 s . c o m Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(activeMQTestQueueA); Message rawMessage = consumer.receive(1000); assertTrue(rawMessage instanceof TextMessage); TextMessage message = (TextMessage) rawMessage; assertEquals("test text", message.getText()); connection.close(); }