package requestor;

import implementation.ClientJMS;


import javax.jms.Queue;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;

import javax.jms.QueueRequestor;
import javax.jms.QueueSession;

import javax.jms.Session;
import javax.jms.TextMessage;


/* Annick Fron
 * Attente d'accuse de reception du message
 */


public class Emetteur extends ClientJMS {


	public static void main(String[] args) {
	
		new Emetteur().run();
	}
	public void run() {

		try {
			QueueConnectionFactory cf=getQueueConnectionFactory();
			QueueConnection connexion= cf.createQueueConnection();
			QueueSession session = connexion.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
			Queue queue = session.createQueue("SampleQ1");
			connexion.start();
			QueueRequestor requestor = new QueueRequestor((QueueSession) session,queue);
			TextMessage mess= session.createTextMessage("Hello");
			System.out.println("Envoi de requete");
			// attente bloquante de reponse
			TextMessage acquittement=(TextMessage)requestor.request( mess);
			System.out.println("acquittement : "+acquittement.getText());
			session.close();
			connexion.close();
		


		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
