1 7 package jfox.test.ejb3.mdb; 8 9 import java.util.Hashtable ; 10 import javax.naming.Context ; 11 import javax.naming.InitialContext ; 12 import javax.jms.QueueConnectionFactory ; 13 import javax.jms.QueueConnection ; 14 import javax.jms.QueueSession ; 15 import javax.jms.Session ; 16 import javax.jms.Queue ; 17 import javax.jms.QueueSender ; 18 19 import org.jfox.framework.Framework; 20 import org.jfox.ejb3.naming.InitialContextFactoryImpl; 21 import org.jfox.ejb3.naming.url.javaURLContextFactory; 22 23 26 public class MDBClient { 27 28 public static void main(String [] args) throws Exception { 29 Framework framework = new Framework(); 31 framework.start(); 32 33 Hashtable <String , String > prop = new Hashtable <String , String >(); 35 prop.put(Context.INITIAL_CONTEXT_FACTORY, InitialContextFactoryImpl.class.getName()); 36 prop.put(Context.OBJECT_FACTORIES, InitialContextFactoryImpl.class.getName()); 37 prop.put(Context.URL_PKG_PREFIXES, javaURLContextFactory.class.getPackage().getName()); 38 prop.put(Context.PROVIDER_URL, "java://localhost"); 39 Context context = new InitialContext (prop); 40 QueueConnectionFactory connectionFactory = (QueueConnectionFactory )context.lookup("defaultcf"); 41 QueueConnection connection = connectionFactory.createQueueConnection(); 42 QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); 43 Queue queue = session.createQueue("testQ"); 44 QueueSender sender = session.createSender(queue); 45 sender.send(session.createTextMessage("Hello, JMS! " + System.currentTimeMillis())); 46 session.close(); 47 connection.close(); 48 49 Thread.sleep(2000); 51 framework.stop(); 52 } 53 } 54 | Popular Tags |