📄 queueexample2sender.java
字号:
/**
* Created on 2003-9-13
*/
package com.liuyang.jboss.message.jms.queue;
import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
/**
* @author
* <a href="mailto:jdcyang@yahoo.com.cn">刘洋</a>
*/
public class QueueExample2Sender {
public static void main(String[] args) throws Exception {
QueueExample1Sender sender = new QueueExample1Sender();
sender.connect();
TextMessage textmsg = sender.session.createTextMessage();
textmsg.setText("QueueExample1Sender"+"发送了一次消息,"+"时间戳:"+System.currentTimeMillis());
sender.send(textmsg);
sender.disconnect();
}
private QueueSender sender;
private QueueConnection conn;
public QueueSession session;
public void connect() throws Exception{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL,"localhost");
Context iniCtx = new InitialContext(env);
Object tmp = iniCtx.lookup("ConnectionFactory");
QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
Queue queue = (Queue)iniCtx.lookup ("queue/queueexample1");
conn = qcf.createQueueConnection();
session = conn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
sender = session.createSender(queue);
}
public void disconnect() throws JMSException{
conn.stop();
session.close();
conn.close();
}
public void send(Message msg) throws JMSException{
sender.send(msg);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -