RequestMDBClient.java
资源名称:MyStore.rar [点击查看]
上传用户:hgs128
上传日期:2007-02-03
资源大小:166k
文件大小:2k
源码类别:
百货/超市行业
开发平台:
WINDOWS
- /*
- * Created on 1999-5-18
- */
- package testClient;
- import java.util.Hashtable;
- import javax.jms.JMSException;
- import javax.jms.ObjectMessage;
- import javax.jms.Queue;
- import javax.jms.QueueConnection;
- import javax.jms.QueueConnectionFactory;
- import javax.jms.QueueSender;
- import javax.jms.QueueSession;
- import javax.naming.InitialContext;
- import javax.naming.NamingException;
- import mdb.RequestItem;
- /**
- * @author 28-9
- *
- * TODO To change the template for this generated type comment go to Window -
- * Preferences - Java - Code Generation - Code and Comments
- */
- public class RequestMDBClient {
- private InitialContext getContext() throws NamingException {
- Hashtable props = new Hashtable();
- props.put(
- InitialContext.INITIAL_CONTEXT_FACTORY,
- "org.jnp.interfaces.NamingContextFactory");
- props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
- InitialContext initialContext = new InitialContext(props);
- return initialContext;
- }
- public void testMDBBean() {
- RequestItem ri = new RequestItem("RUSTY", "PASSWD", "14", 30);
- System.out.println("Looking up the factory ");
- try {
- InitialContext ctx = getContext();
- QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
- System.out.println("Looking up the queue");
- Queue queue = (Queue) ctx.lookup("queue/MdbQueue");
- System.out.println("Creating the connction now...");
- QueueConnection conn = factory.createQueueConnection();
- System.out.println("Creating the session now...");
- QueueSession session = conn.createQueueSession(true, 1);
- System.out.println("Creating the sender now...");
- QueueSender sender = session.createSender(queue);
- ObjectMessage message = session.createObjectMessage();
- System.out.println("Setting the object in message now....");
- message.setObject(ri);
- System.out.println("Sending the message ");
- sender.send(message);
- System.out.println("Shuting down");
- session.commit();
- conn.close();
- System.out.println("Finished");
- } catch (NamingException e) {
- System.out.println(e.getMessage());
- e.printStackTrace();
- } catch (JMSException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void main(String[] args) {
- RequestMDBClient mdbean = new RequestMDBClient();
- mdbean.testMDBBean();
- }
- }