package hierarchie.topic;

import implementation.ClientJMS;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;

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

/* Annick Fron
 * A lancer apres le recepteur
 * L'emetteur envoie des mesasges sur deux topics differents
 * dans la meme session
 */
public class Emetteur extends ClientJMS {


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

		try {
			ConnectionFactory cf=getConnectionFactory();
			Connection connexion= cf.createConnection();
			Session session = connexion.createSession(false, Session.AUTO_ACKNOWLEDGE);
			sendTopic(session, "Sport.Football");
			sendTopic(session, "Sport.Tennis");
			session.close();
			connexion.close();
			System.out.println("Message envoye");


		} catch (JMSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void sendTopic(Session session, String topicName) throws JMSException {
		Destination topic1 = session.createTopic(topicName);
		MessageProducer sender = session.createProducer(topic1);
		TextMessage mess= session.createTextMessage("Hello "+topicName);
		sender.send( mess);

	}
}
