⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmproducer.java

📁 网络购物系统开发详细步骤
💻 JAVA
字号:
package jms.client;

import javax.jms.QueueConnectionFactory;
import javax.jms.*;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.Queue;
import javax.jms.QueueSender;
import javax.jms.TextMessage;
import javax.jms.JMSException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import java.util.Properties;

public class QMProducer {
  public static void main(String[] args) {
    Properties jndiEnv = new Properties();
    jndiEnv.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                        "weblogic.jndi.WLInitialContextFactory");
    jndiEnv.setProperty(Context.PROVIDER_URL, "t3://localhost:7001");
    QueueConnection con = null;
    QueueSession session = null;
    QueueSender sender = null;
    try {
      Context ctx = new InitialContext(jndiEnv);
      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup(
          "jms/QueueConnectionFactory");
      con = factory.createQueueConnection();
      session = con.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      Queue q = (Queue) ctx.lookup("jms/fileQueue");
      sender = session.createSender(q);
      TextMessage msg = session.createTextMessage();
      msg.setText("Hello World");
      sender.send(msg);
    }
    catch (NamingException ne) {
      ne.printStackTrace();
    }
    catch (JMSException je) {
      je.printStackTrace();
    }
    finally{
      if(sender !=null)try{sender.close();}catch(JMSException je){}
      if(session !=null)try{session.close();}catch(JMSException je){}
      if(con !=null)try{con.close();}catch(JMSException je){}

    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -