这个应该是JMS Provider做的事情吧
解决方案 »
- 关于面向对象,两年了还是没弄明白
- java网站的一个怪问题
- ibatis 中查询结果涉及到多个数据表中的字段, 如何写resultMap???
- java怎样实现邮件订阅功能
- jetspeed单点登陆,权限问题!
- Struts2与uploadify图片上传的问题
- 我的这个applicationcontext有问题吗
- 请问如何在xml中加入<符号
- resin-3.0怎么在启动的时候设置java虚拟机内存大小
- 请问谁做过有关j2ee的比较完整的例子
- Wanna to learn J2EE, start from Servlet and JSP installing?Help!!!
- 寻找j2ee相关的中英文对照翻译文献,请help,多谢!
sender.send(textmessage,javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY,1800000);
你先send一个消息,然后关闭服务器,再重启,执行Receiver程序
消息还是可以成功接收。
也对!
默认的sender.send(textmessage)就是采用DeliveryMode.PERSISTENT模式;
DEFAULT_PRIORITY为4。
<jms-server port="9127">
<!-- Queue bindings, these queues will be bound to their respective JNDI path for
later retrieval -->
<queue name="Demo Queue" location="jms/demoQueue">
<description>A dummy queue</description>
</queue>
<queue name="Table Queue" location="jms/theQueue" persistence-file="../persistence/jms/tableQueue.queue">
<description>A dummy queue</description>
</queue>
<queue-connection-factory host="192.168.0.119" location="jms/theQueueConnectionFactory" password="123" port="9127" username="admin" />
<!-- Topic bindings, these topic will be bound to their respective JNDI path for
later retrieval -->
<topic name="Demo Topic" location="jms/demoTopic">
<description>A dummy topic</description>
</topic> <!-- path to the log-file where JMS-events/errors are stored -->
<log>
<file path="../log/jms.log" />
</log>
</jms-server>
如果用sun J2EE RI是非常简单的!
原理当然一样了,JMS是独立于Provider的。
其实最主要是先配置好destination和connectionFactory;
然后再用JNDI查找,以下是两个基于sun J2EE RI
的简单程序(21天学通J2EE上的例子),可以参考一下:sender:import javax.naming.*;
import javax.jms.*;public class PTPSender {
private QueueConnection queueConnection;
private QueueSession queueSession;
private QueueSender queueSender;
private Queue queue; public static void main(String[] arge) {
try {
PTPSender sender=new PTPSender();
System.out.println("Sending message Hello World");
sender.sendMessage("Hello World");
sender.close();
} catch(Exception e) {
System.err.println("Exception in PTPSender: "+e);
}
} public PTPSender() throws JMSException,NamingException {
Context context=new InitialContext();
QueueConnectionFactory queueFactory=(QueueConnectionFactory)context.lookup("jms/QueueConnectionFactory");
queueConnection=queueFactory.createQueueConnection();
queueSession=queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queue=(Queue)context.lookup("jms/Queue");
queueSender=queueSession.createSender(queue);
} public void sendMessage(String msg) throws JMSException {
TextMessage message=queueSession.createTextMessage();
message.setText(msg);
queueSender.send(message);
} public void close() throws JMSException {
queueSender.send(queueSession.createMessage());
queueSender.close();
queueSession.close();
queueConnection.close();
}
}receiver:import javax.naming.*;
import javax.jms.*;public class PTPReceiver {
private QueueConnection queueConnection;
private QueueSession queueSession;
private QueueReceiver queueReceiver;
private Queue queue; public static void main(String[] arge) {
try {
PTPReceiver receiver=new PTPReceiver();
System.out.println("Receiver running");
String textMsg=receiver.consumeMessage();
if(textMsg!=null)
System.out.println("Received: "+textMsg);
receiver.close();
//Thread.currentThread().sleep(120000);
} catch(Exception e) {
System.err.println("Exception in PTPSender: "+e);
}
} public PTPReceiver() throws JMSException,NamingException {
Context context=new InitialContext();
QueueConnectionFactory queueFactory=(QueueConnectionFactory)context.lookup("jms/QueueConnectionFactory");
queueConnection=queueFactory.createQueueConnection();
queueSession=queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queue=(Queue)context.lookup("jms/Queue");
queueReceiver=queueSession.createReceiver(queue);
queueConnection.start();
} public String consumeMessage() throws JMSException {
String text=null;
Message message=queueReceiver.receive();
if(message instanceof TextMessage) {
text=((TextMessage)message).getText();
}
return text;
} public void close() throws JMSException {
queueReceiver.close();
queueSession.close();
queueConnection.close();
}
}
所以我打算换一种消息服务器,请大家帮我推荐一种!
所以我打算换一种消息服务器,请大家帮我推荐一种!
所以我打算换一种消息服务器,请大家帮我推荐一种!
如果想要单纯的消息服务器可以试试IBM的MQ Series,
其他具体情况可以在网上看看。
tomcat+openjms