refurl:http://wenku.baidu.com/view/f6f580c3d5bbfd0a79567336.html
http://aspnetdb.iteye.com/blog/1179469
http://junier.iteye.com/blog/453420 --点对点的
注意点:
1、JMS发送是要用到服务器的,要用ActiveMQ或者OpejJMS作为服务器
下载apache-activemq-5.2.0-bin.zip:http://download.huihoo.com/apache/activemq/20081221-207.html
其他参考资料:
refurl:http://flyer2010.iteye.com/blog/662047 (含JMS简单小例子)
--Oracle官方JMS教程
http://download.oracle.com/otn-pub/jcp/7195-jms-1.1-fr-spec-oth-JSpec/jms-1_1-fr-spec.pdf
--还有就是【Java消息服务第二版这本书】
http://blog.csdn.net/yutel/article/details/3874439 --此书中提到jms有2种模式,一种是队列,一种是点对点。在我看来,广播群发消息就用队列,即时聊天就用点对点
附源码如下:启动时要加3个参数
package testJms; import java.io.*; import javax.jms.*; import javax.naming.*; public class Chat implements javax.jms.MessageListener { private TopicSession pubSession; private TopicPublisher publisher; private TopicConnection connection; private String username; /* Constructor used to Initialize Chat */ public Chat(String topicFactory, String topicName, String username)throws Exception { // Obtain a JNDI connection using the jndi.properties file InitialContext ctx = new InitialContext(); // Look up a JMS connection factory and create the connection TopicConnectionFactory conFactory = (TopicConnectionFactory)ctx.lookup(topicFactory); TopicConnection connection = conFactory.createTopicConnection(); // Create two JMS session objects TopicSession pubSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSession subSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); // Look up a JMS topic Topic chatTopic = (Topic)ctx.lookup(topicName); // Create a JMS publisher and subscriber. The additional parameters // on the createSubscriber are a message selector (null) and a true // value for the noLocal flag indicating that messages produced from // this publisher should not be consumed by this publisher. TopicPublisher publisher = pubSession.createPublisher(chatTopic); TopicSubscriber subscriber = subSession.createSubscriber(chatTopic, null, true); // Set a JMS message listener subscriber.setMessageListener(this); // Intialize the Chat application variables this.connection = connection; this.pubSession = pubSession; this.publisher = publisher; this.username = username; // Start the JMS connection; allows messages to be delivered connection.start(); } /* Receive Messages From Topic Subscriber */ public void onMessage(Message message) { try { TextMessage textMessage = (TextMessage) message; System.out.println(textMessage.getText()); } catch (JMSException jmse){ jmse.printStackTrace(); } } /* Create and Send Message Using Publisher */ protected void writeMessage(String text) throws JMSException { TextMessage message = pubSession.createTextMessage(); message.setText(username+": "+text); publisher.publish(message); } /* Close the JMS Connection */ public void close() throws JMSException { connection.close(); } /* Run the Chat Client */ public static void main(String [] args) { try { if (args.length!=3) System.out.println("Factory, Topic, or username missing"); // args[0]=topicFactory; args[1]=topicName; args[2]=username Chat chat = new Chat(args[0],args[1],args[2]); // Read from command line BufferedReader commandLine = new java.io.BufferedReader(new InputStreamReader(System.in)); // Loop until the word "exit" is typed while(true) { String s = commandLine.readLine(); if (s.equalsIgnoreCase("exit")){ chat.close(); System.exit(0); } else chat.writeMessage(s); } } catch (Exception e) { e.printStackTrace(); } } } ======================================================================= ps:又发现一个JMS好教程的地方,我已经粗略浏览过几篇,讲的不错: http://www.360doc.com/content/09/0712/20/18042_4241628.shtml
相关推荐
JMS例子.docx JMS例子.docx JMS例子.docx
activeMQ JMS WEB 例子
关于java的jms的一个小例子,对jms使用的应用。。。
jms的应用例子,对您可能有所帮助。 支持一下吧。很好的例子哟
JMS OPENJMS的实现例子JMS OPENJMS的实现例子JMS OPENJMS的实现例子JMS OPENJMS的实现例子
JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS(JMS
本例详细介绍了如何配置JMS服务以及weblogic的安装及在weblogic中配置JMS服务,例子简单易懂,文档含代码,适合初学者学习使用
JMS开发例子.pdf
JMS开发例子,里面介绍JMS如何开发,如何编写客户端和服务端,以及通信原理
JMS入门(一)从简单示例开始 http://blog.csdn.net/lucien_zong/article/details/17204645
JBOSS建立JMS应用实例 代码 + 文档
含有八个独立运行的程序,分别设计JMS多个方面。 工程使用ActiveMQ,运行工程之前,请阅读doc.txt文档,并运行ActiveMQ
Spring发送接收JMS消息 文档+例子
jms 案例对于初学者很有用的偶,很简单很使用的例子
Classes contained in javax.jms.jar: javax.transaction.xa.XAResource.class javax.jms.BytesMessage.class javax.jms.Message.class javax.jms.JMSException.class javax.jms.Destination.class javax.jms....
javax.jms.BytesMessage.class javax.jms.Connection.class javax.jms.ConnectionConsumer.class javax.jms.ConnectionFactory.class javax.jms.ConnectionMetaData.class javax.jms.DeliveryMode.class javax.jms....
Java jms处理消息请求的例子,Java创建和初始化一个请求Requestor对象,初始化请求Requestor对象,接受由反馈者replier发回的消息,响应request产生要输出的信息,输出响应信息。
ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息...ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久的事情了,但是JMS在当今的J2EE应用中间仍然扮演着特殊的地位。
文件包含: 13个不同固件 两个固件升级工具 其中一个是量产工具可以修改休眠时间和盒子信息 TRIM检查工具 有几个固件版本为全网首发,别人没有的资源 固件列表: JMS578_00.01.00.05 ...JMS578_254.02.03.09_NoUAS