Java examples for Message:JMS
Create JMS Destination
import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Session; import javax.jms.TextMessage; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; public class Receiver { public static void main(String[] args) {/*from w w w.j a v a 2 s . c om*/ ConnectionFactory connectionFactory; try { connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://172.16.0.191:61616"); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("com.balintimes.Queue"); MessageConsumer consumer = session.createConsumer(destination); TextMessage message; while (true) { message = (TextMessage) consumer.receive(500000); if (message != null) { System.out.println("got :" + message.getText()); } else { System.out.println("null"); break; } } session.commit(); } catch (Exception e) { System.out.println(e.getMessage()); } } }