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

📄 simplemessageclient.java

📁 JavaeeTutorial5的源代码。
💻 JAVA
字号:
/* * Copyright 2007 Sun Microsystems, Inc. * All rights reserved.  You may not modify, use, * reproduce, or distribute this software except in * compliance with  the terms of the License at: * http://developer.sun.com/berkeley_license.html */import javax.jms.ConnectionFactory;import javax.jms.Destination;import javax.jms.Queue;import javax.jms.Connection;import javax.jms.Session;import javax.jms.MessageProducer;import javax.jms.TextMessage;import javax.jms.JMSException;import javax.annotation.Resource;public class SimpleMessageClient {    @Resource(mappedName = "jms/ConnectionFactory")    private static ConnectionFactory connectionFactory;    @Resource(mappedName = "jms/Queue")    private static Queue queue;    public static void main(String[] args) {        Connection connection = null;        Session session = null;        MessageProducer messageProducer = null;        TextMessage message = null;        final int NUM_MSGS = 3;        try {            connection = connectionFactory.createConnection();            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);            messageProducer = session.createProducer(queue);            message = session.createTextMessage();            for (int i = 0; i < NUM_MSGS; i++) {                message.setText("This is message " + (i + 1));                System.out.println("Sending message: " + message.getText());                messageProducer.send(message);            }            System.out.println("To see if the bean received the messages,");            System.out.println(                    " check <install_dir>/domains/domain1/logs/server.log.");        } catch (JMSException e) {            System.out.println("Exception occurred: " + e.toString());        } finally {            if (connection != null) {                try {                    connection.close();                } catch (JMSException e) {                }            } // if            System.exit(0);        } // finally    } // main} // class

⌨️ 快捷键说明

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