Guest User

Jim

a guest
Nov 12th, 2010
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. private static void testOptimizedConsumer() {
  2.  
  3.     try {
  4.       logger.info(getDate() + " starting test...");
  5.       Connection qConnection = null;
  6.       Session session = null;
  7.       MessageConsumer messageConsumer = null;
  8.  
  9.       String broker = "failover:(tcp://cache07:61616)";
  10.       ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(broker);
  11.      
  12.       connectionFactory.setOptimizeAcknowledge(true);
  13.       connectionFactory.setAlwaysSessionAsync(false);
  14.  
  15.       qConnection = connectionFactory.createConnection();
  16.       qConnection.start();
  17.  
  18.       session = qConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
  19.  
  20.       Destination destination = session.createQueue("benchmarks2");
  21.  
  22.       messageConsumer = session.createConsumer(destination);
  23.  
  24.       TextMessage messageReceived = null;
  25.       int i = 0;
  26.       int numberOfMessages = 100000;
  27.       while (i < numberOfMessages) {
  28.         i++;
  29.         messageReceived = (TextMessage) messageConsumer.receive(10000);
  30.         String msg = messageReceived.getText();
  31.  
  32.         logger.info(msg);
  33.       }
  34.  
  35.       logger.info(getDate() + " optimized consumer test over. dequeued: " + numberOfMessages + " messages");
  36.  
  37.     } catch (JMSException e) {
  38.       logger.error(e.toString(), e);
  39.       throw new RuntimeException(e);
  40.     }
  41.   }
Advertisement
Add Comment
Please, Sign In to add comment