Advertisement
kdelemme

ActiveMQ Consumer

May 29th, 2012
1,619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package com.profiler.consumer;
  2.  
  3. import javax.jms.*;
  4.  
  5. import org.apache.activemq.ActiveMQConnection;
  6. import org.apache.activemq.ActiveMQConnectionFactory;
  7.  
  8.  
  9. public class Consumer {
  10.     public static TextListener listener;
  11.     // = localhost
  12.     private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
  13.     // Name of the queue
  14.     private static String subject = "Profiler";
  15.  
  16.     public static void main(String[] args) throws JMSException {
  17.         // Getting JMS connection from the server
  18.         ConnectionFactory connectionFactory  = new ActiveMQConnectionFactory(url);
  19.         Connection connection = connectionFactory.createConnection();
  20.        
  21.         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  22.         Destination destination = session.createQueue(subject);
  23.         MessageConsumer consumer = session.createConsumer(destination);
  24.         connection.start();
  25.        
  26.         listener = new TextListener();
  27.         consumer.setMessageListener(listener);
  28.     }
  29.    
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement