Single point of transmission--the corresponding data channel for messages is queue queues, message producer Queuesender and message consumers QueueReceiver
 
 
 
JAVAX.JMS public 
Interface Queuesender extends MessageProducer public interface QueueReceiver extends
Messageconsumer
 
 
The interface associated with the queue is also:
 
 
JAVAX.JMS public
Interface Queueconnectionfactory extends ConnectionFactory public
interface Queueconnection Extends Connection public
interface Queuesession extends session
 
 
(Session and connection need to be closed after use.)
 
you need to open Connection,connection.start () before the message is received.
 
The model for point-to-point communication is as follows:
 
 
 
The programming model for point-to-point JMS applications is as follows:
 
 
 
Example:
 
We manually go to send message to queue through the active MQ Admin portlet, creating two consumer in the code to receive the message asynchronously.
 
The consumer code is as follows:
 
 
Package com.gof.jms.test;
Import javax.jms.Connection;
Import Javax.jms.ConnectionFactory;
Import Javax.jms.DeliveryMode;
Import javax.jms.Destination;
Import javax.jms.JMSException;
Import Javax.jms.Message;
Import Javax.jms.MessageConsumer;
Import Javax.jms.MessageListener;
Import Javax.jms.MessageProducer;
Import javax.jms.Session;
Import Javax.jms.TextMessage;
Import Org.apache.activemq.ActiveMQConnectionFactory;
	public class Queuemessageapp {public static final String user = ' System ';
	public static final String password = "Manager";
	public static final String URL = "tcp://localhost:61616";
	public static final String queuename = "Test_queue";
	public static Final Boolean transacted = false;
	
    public static Final Boolean persistent = false;
    	public static void Main (string[] args) {Connection Connection = null;
    	
    	Session session = NULL; try{//Create the connection connectionfactory connectionfactory = new Activemqconnectionfactory (user, password, URL);
            Connection = Connectionfactory.createconnection ();
            
            Connection.start ();
            Create the session session = Connection.createsession (transacted, Session.auto_acknowledge);
            
            Destination Destination = Session.createqueue (queuename);
            
            In this example, we'll send the message through ACTIVEMQ admin portlet manually.
            Create the consumer1 messageconsumer consumer1 = session.createconsumer (destination); Consumer1.setmessagelistener (New MessageListener () {public void OnMessage (Message message) {//TODO Auto-genera
					Ted Method Stub TextMessage recvmessage = (textmessage) message;
					try{System.out.println ("Receive message by the 1st Consumer:" + recvmessage.gettext ());
					}catch (jmsexception e) {e.printstacktrace ();
            
            }
				}
			}); Create the Consumer2 MessaGeconsumer consumer2 = Session.createconsumer (destination); Consumer2.setmessagelistener (New MessageListener () {public void OnMessage (Message message) {//TODO Auto-genera
					Ted Method Stub TextMessage recvmessage = (textmessage) message;
					try{System.out.println ("Receive message by the 2nd Consumer:" + recvmessage.gettext ());
					}catch (jmsexception e) {e.printstacktrace ();
            
            }
				}
			});
            To avoid the connection closed before the message listener received.
            
    	Thread.Sleep (5000000);
    	}catch (Exception e) {e.printstacktrace ();
    		    }finally{try{//close sessions and connection if (session!= null) {session.close ();
    		    } if (connection!= null) {connection.close ();
    		}}catch (Exception e) {e.printstacktrace ();
 }
    	}
    }
} 
 
Start Active MQ First, then start the consumer program above.
 
Manually send queue messages to target queue in active MQ Admin porlet.
 
 
 
You can get the following program output:
 
 
 
It can be seen that each message is consumed only once, and if multiple consumers are listening to a queue at the same time, it is not possible to determine which consumer will eventually be consumed by a message .