- 浏览: 214798 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (397)
- j2se (28)
- nio (3)
- 易错点 (3)
- 面试ssh (9)
- ssh整合 (11)
- jbpm+spring (2)
- js (15)
- 高级技术 (59)
- swing (3)
- 数据库 (16)
- hibernate (18)
- spring (19)
- 开发网站知识点 (9)
- jbpm (4)
- json (5)
- 设计模式 (22)
- 自定义标签 (1)
- j2ee (9)
- lucene (3)
- cahce (11)
- maven (5)
- html5 (1)
- 多数据源 (10)
- 页面聊天 (9)
- 富客户端 (1)
- android (13)
- aop+拦截器+jms (13)
- 框架整合 (1)
- 非阻塞io (24)
- 暂时不看 (13)
- webservice (3)
- oracle (3)
- 算法 (4)
- 协程 (2)
- netty (1)
- 爬虫 (0)
- 高级基础 (1)
- JVM调优总结 (12)
- 知识点技巧 (1)
- REST (0)
- 基础 io (2)
- dubbo (8)
- 线程 (1)
- spring源码 (2)
- git (1)
- office (2)
最新评论
-
sjzcmlt:
,写的挺好的啊
一个完整的负载均衡的例子 . -
他大姨妈:
网上大部分例子都是直接通过IdleStateHandler来实 ...
Netty的超时机制 心跳机制
package com.xmddl.jms.demo; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Hashtable; import javax.jms.BytesMessage; import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.ObjectMessage; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueSender; import javax.jms.QueueSession; import javax.jms.Session; import javax.jms.StreamMessage; import javax.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class QueueSend { // Defines the JNDI context factory. public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; // Defines the JNDI provider url. public final static String PROVIDER_URL = "t3://localhost:7001"; // Defines the JMS connection factory for the queue. public final static String JMS_FACTORY = "SendJMSFactory"; // Defines the queue. public final static String QUEUE = "SendJMSQueue"; private QueueConnectionFactory qconFactory; private QueueConnection qcon; private QueueSession qsession; private QueueSender qsender; private Queue queue; private TextMessage msg; private StreamMessage sm; private BytesMessage bm; private MapMessage mm; private ObjectMessage om; /** * Creates all the necessary objects for sending messages to a JMS queue. * * @param ctx * JNDI initial context * @param queueName * name of queue * @exception NamingException * if operation cannot be performed * @exception JMSException * if JMS fails to initialize due to internal error */ public void init(Context ctx, String queueName) throws NamingException, JMSException { qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY); qcon = qconFactory.createQueueConnection(); qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queue = (Queue) ctx.lookup(queueName); qsender = qsession.createSender(queue); msg = qsession.createTextMessage(); sm = qsession.createStreamMessage(); bm = qsession.createBytesMessage(); mm = qsession.createMapMessage(); om = qsession.createObjectMessage(); qcon.start(); } /** * Sends a message to a JMS queue. * * @param message * message to be sent * @exception JMSException * if JMS fails to send message due to internal error */ public void send(String message) throws JMSException { // set TextMessage msg.setText(message); // set StreamMessage sm.writeString("xmddl369"); sm.writeDouble(23.33); // set BytesMessage String name = "xmddl369"; byte[] block = name.getBytes(); bm.writeBytes(block); // set MapMessage mm.setString("name", "xmddl369"); // set ObjectMessage UserInfo ui = new UserInfo(); ui.setName("xmddl369"); ui.setAddress("厦门"); ui.setAge(100); om.setObject(ui); // qsender.send(msg); // qsender.send(sm); // qsender.send(bm); // qsender.send(mm); qsender.send(om); } /** * Closes JMS objects. * * @exception JMSException * if JMS fails to close objects due to internal error */ public void close() throws JMSException { qsender.close(); qsession.close(); qcon.close(); } public static void main(String[] args) throws Exception { InitialContext ic = getInitialContext(); QueueSend qs = new QueueSend(); qs.init(ic, QUEUE); readAndSend(qs); qs.close(); } private static void readAndSend(QueueSend qs) throws IOException, JMSException { BufferedReader msgStream = new BufferedReader(new InputStreamReader( System.in)); String line = null; boolean quitNow = false; do { System.out.print("Enter message (\"quit\" to quit): "); line = msgStream.readLine(); if (line != null && line.trim().length() != 0) { qs.send(line); System.out.println("JMS Message Sent: " + line + "\n"); quitNow = line.equalsIgnoreCase("quit"); } } while (!quitNow); } private static InitialContext getInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, PROVIDER_URL); return new InitialContext(env); } }
package com.xmddl.jms.demo; import java.util.Hashtable; import javax.jms.BytesMessage; import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueReceiver; import javax.jms.QueueSession; import javax.jms.Session; import javax.jms.StreamMessage; import javax.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; /** * * @author Administrator * <pre> * 修改版本: 修改人: 修改日期: 修改内容: * </pre> */ public class QueueReceive implements MessageListener { // Defines the JNDI context factory. public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; // Defines the JNDI provider url. public final static String PROVIDER_URL = "t3://localhost:7001"; // Defines the JMS connection factory for the queue. public final static String JMS_FACTORY = "SendJMSFactory"; // Defines the queue. public final static String QUEUE = "SendJMSQueue"; private QueueConnectionFactory qconFactory; private QueueConnection qcon; private QueueSession qsession; private QueueReceiver qreceiver; private Queue queue; private boolean quit = false; /** * Message listener interface. * * @param msg * message */ public void onMessage(Message msg) { try { String msgText = ""; double d = 0; if (msg instanceof TextMessage) { msgText = ((TextMessage) msg).getText(); } else if (msg instanceof StreamMessage) { msgText = ((StreamMessage) msg).readString(); d = ((StreamMessage) msg).readDouble(); } else if (msg instanceof BytesMessage) { byte[] block = new byte[1024]; ((BytesMessage) msg).readBytes(block); msgText = String.valueOf(block); } else if (msg instanceof MapMessage) { msgText = ((MapMessage) msg).getString("name"); } else if (msg instanceof ObjectMessage) { UserInfo ui = (UserInfo) ((ObjectMessage) msg).getObject(); msgText = ui.getName(); d = ui.getAge(); } System.out.println("Message Received: " + msgText + "\t" + d); if (msgText.equalsIgnoreCase("quit")) { synchronized (this) { quit = true; this.notifyAll(); // Notify main thread to quit } } } catch (JMSException jmse) { jmse.printStackTrace(); } } /** * Creates all the necessary objects for receiving messages from a JMS * queue. * * @param ctx * JNDI initial context * @param queueName * name of queue * @exception NamingException * if operation cannot be performed * @exception JMSException * if JMS fails to initialize due to internal error */ public void init(Context ctx, String queueName) throws NamingException, JMSException { qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY); qcon = qconFactory.createQueueConnection(); qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); queue = (Queue) ctx.lookup(queueName); qreceiver = qsession.createReceiver(queue); qreceiver.setMessageListener(this); qcon.start(); } /** * Closes JMS objects. * * @exception JMSException * if JMS fails to close objects due to internal error */ public void close() throws JMSException { qreceiver.close(); qsession.close(); qcon.close(); } /** * main() method. * * @param args * WebLogic Server URL * @exception Exception * if execution fails */ public static void main(String[] args) throws Exception { InitialContext ic = getInitialContext(); QueueReceive qr = new QueueReceive(); qr.init(ic, QUEUE); System.out .println("JMS Ready To Receive Messages (To quit, send a \"quit\" message)."); // Wait until a "quit" message has been received. synchronized (qr) { while (!qr.quit) { try { qr.wait(); } catch (InterruptedException ie) { ie.printStackTrace(); } } } qr.close(); } private static InitialContext getInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, PROVIDER_URL); return new InitialContext(env); } public String getEncoding() throws Exception { return "Hello World!"; } }
package com.xmddl.jms.demo; import java.io.Serializable; public class UserInfo implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private String name; private String address; private double age; public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public double getAge() { return age; } public void setAge(double age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
2.PUB/SUB模型应用
package com.xmddl.jms.demo; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Hashtable; import javax.jms.BytesMessage; import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.ObjectMessage; import javax.jms.Session; import javax.jms.StreamMessage; import javax.jms.TextMessage; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicPublisher; import javax.jms.TopicSession; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class TopicSend { // Defines the JNDI context factory. public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; // Defines the JNDI provider url. public final static String PROVIDER_URL = "t3://localhost:7001"; // Defines the JMS connection factory for the queue. public final static String JMS_FACTORY = "SendJMSFactory"; // Defines the queue. public final static String TOPIC= "SendJMSTopic"; private TopicConnectionFactory qconFactory; private TopicConnection qcon; private TopicSession qsession; private TopicPublisher publisher; private Topic topic; private TextMessage msg; private StreamMessage sm; private BytesMessage bm; private MapMessage mm; private ObjectMessage om; public void init(Context ctx, String queueName) throws NamingException, JMSException { qconFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY); qcon = qconFactory.createTopicConnection(); // qsession = qcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); qsession = qcon.createTopicSession(true, Session.AUTO_ACKNOWLEDGE); topic = (Topic) ctx.lookup(queueName); publisher = qsession.createPublisher(topic); msg = qsession.createTextMessage(); sm=qsession.createStreamMessage(); bm=qsession.createBytesMessage(); mm=qsession.createMapMessage(); om=qsession.createObjectMessage(); qcon.start(); } /** * Sends a message to a JMS queue. * * @param message * message to be sent * @exception JMSException * if JMS fails to send message due to internal error */ public void send(String message) throws JMSException { //set TextMessage msg.setText(message); //set StreamMessage sm.writeString("xmddl369"); sm.writeDouble(23.33); //set BytesMessage String name="xmddl369"; byte[] block=name.getBytes(); bm.writeBytes(block); //set MapMessage mm.setString("name", "xmddl369"); //set ObjectMessage UserInfo ui=new UserInfo(); ui.setName("xmddl369"); ui.setAddress("厦门"); ui.setAge(100); om.setObject(ui); // qsender.send(msg); // qsender.send(sm); // qsender.send(bm); // qsender.send(mm); publisher.publish(om); // qsession.commit(); } /** * Closes JMS objects. * * @exception JMSException * if JMS fails to close objects due to internal error */ public void close() throws JMSException { publisher.close(); qsession.close(); qcon.close(); } public static void main(String[] args) throws Exception { InitialContext ic = getInitialContext(); TopicSend qs = new TopicSend(); qs.init(ic, TOPIC); readAndSend(qs); qs.close(); } private static void readAndSend(TopicSend qs) throws IOException, JMSException { BufferedReader msgStream = new BufferedReader(new InputStreamReader( System.in)); String line = null; boolean quitNow = false; do { System.out.print("Enter message (\"quit\" to quit): "); line = msgStream.readLine(); if (line != null && line.trim().length() != 0) { qs.send(line); System.out.println("JMS Message Sent: " + line + "\n"); quitNow = line.equalsIgnoreCase("quit"); } } while (!quitNow); } private static InitialContext getInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, PROVIDER_URL); return new InitialContext(env); } }
package com.xmddl.jms.demo; import java.util.Hashtable; import javax.jms.BytesMessage; import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.ObjectMessage; import javax.jms.Session; import javax.jms.StreamMessage; import javax.jms.TextMessage; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicSession; import javax.jms.TopicSubscriber; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class TopicReceive implements MessageListener{ // Defines the JNDI context factory. public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory"; // Defines the JNDI provider url. public final static String PROVIDER_URL = "t3://localhost:7001"; // Defines the JMS connection factory for the queue. public final static String JMS_FACTORY = "SendJMSFactory"; // Defines the queue. public final static String TOPIC= "SendJMSTopic"; private TopicConnectionFactory qconFactory; private TopicConnection qcon; private TopicSession qsession; private TopicSubscriber subscriber; private Topic topic; private TextMessage msg; private boolean quit = false; public void onMessage(Message msg) { try { String msgText = ""; double d = 0; if (msg instanceof TextMessage) { msgText = ((TextMessage) msg).getText(); } else if (msg instanceof StreamMessage) { msgText = ((StreamMessage) msg).readString(); d = ((StreamMessage) msg).readDouble(); } else if (msg instanceof BytesMessage) { byte[] block = new byte[1024]; ((BytesMessage) msg).readBytes(block); msgText = String.valueOf(block); } else if (msg instanceof MapMessage) { msgText = ((MapMessage) msg).getString("name"); } else if (msg instanceof ObjectMessage) { UserInfo ui = (UserInfo) ((ObjectMessage) msg).getObject(); msgText = ui.getName(); d = ui.getAge(); } System.out.println("Message Received: " + msgText + "\t" + d); if (msgText.equalsIgnoreCase("quit")) { synchronized (this) { quit = true; this.notifyAll(); // Notify main thread to quit } } } catch (JMSException jmse) { jmse.printStackTrace(); } } /** * Creates all the necessary objects for receiving messages from a JMS * queue. * * @param ctx * JNDI initial context * @param queueName * name of queue * @exception NamingException * if operation cannot be performed * @exception JMSException * if JMS fails to initialize due to internal error */ public void init(Context ctx, String queueName) throws NamingException, JMSException { qconFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY); qcon = qconFactory.createTopicConnection(); qsession = qcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = (Topic) ctx.lookup(queueName); subscriber = qsession.createSubscriber(topic); subscriber.setMessageListener(this); qcon.start(); } /** * Closes JMS objects. * * @exception JMSException * if JMS fails to close objects due to internal error */ public void close() throws JMSException { subscriber.close(); qsession.close(); qcon.close(); } /** * main() method. * * @param args * WebLogic Server URL * @exception Exception * if execution fails */ public static void main(String[] args) throws Exception { InitialContext ic = getInitialContext(); TopicReceive qr = new TopicReceive(); qr.init(ic, TOPIC); System.out .println("JMS Ready To Receive Messages (To quit, send a \"quit\" message)."); // Wait until a "quit" message has been received. synchronized (qr) { while (!qr.quit) { try { qr.wait(); } catch (InterruptedException ie) { ie.printStackTrace(); } } } qr.close(); } private static InitialContext getInitialContext() throws NamingException { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, PROVIDER_URL); return new InitialContext(env); } public String getEncoding() throws Exception { return "Hello World!"; } }
说明:点对点的消息只能被一个人消费一次,发布和订阅的消息可以被多个人消费一次。SendJMSFactory和SendJMSTopic等要通过JNDI从weblogic中查找......
发表评论
-
深入掌握JMS(十一):TemporaryQueue和TemporaryTopic
2014-10-30 09:15 0TemporaryQueue和TemporaryTopi ... -
深入掌握JMS(十):JMSCorrelationID与Selector
2014-10-30 09:14 0前面讲过JMSCorrelationID主要是用来关联多个M ... -
深入掌握JMS(九):Selector
2014-10-30 09:14 0前面的例子中创建一个消息消费者使用的是: ... -
深入掌握JMS(八):JMSReplyTo
2014-10-30 09:13 0在下面的例子中,首先创建两个Queue,发送者给一个Queu ... -
深入掌握JMS(七):DeliveryMode例子
2014-10-30 09:13 0在下面的例子中,分别发送一个Persistent和nonp ... -
深入掌握JMS(四):实战Queue
2014-10-30 09:12 383Queue实现的是点到点模型,在下面的例子中,启动2个消费者 ... -
深入掌握JMS(三):MessageListener
2014-10-30 09:12 461消息的消费者接收消息可以采用两种方式: ... -
深入掌握JMS(二):一个JMS例子
2014-10-30 09:11 339前一讲简单的介绍了一 ... -
深入掌握JMS(一):JSM基础
2014-10-30 09:11 4501. JMS基本概念 JMS ... -
java事件机制
2014-10-27 17:04 347java事件机制包括三个部分:事件、事件监听器、事件源。 ... -
cxf+spring
2014-10-26 13:40 454WEB-INF/applicationContext.xm ... -
spring 拦截器
2014-07-05 23:53 607<!-- 拦截器1 --> <bea ... -
spring aop
2014-07-05 23:53 479<context:annotation-config ... -
3种方式实现AOP
2014-06-25 09:44 423一、代理模式实现aop ? -
jndi调用时,各种应用服务器InitialContext的写法
2014-06-14 10:36 487调用ejb时,如果客户端 ... -
spring+jms
2014-05-13 10:15 570<?xml version="1.0&quo ... -
动态静态代理 jdk cglib
2014-04-10 13:22 638静态代理 由程序 ...
相关推荐
接着,使用WLST(WebLogic Scripting Tool)进行服务器实例的创建和配置,包括数据源、JMS资源等。最后,启动WebLogic Server,通过管理控制台验证配置。 Oracle数据库是全球广泛使用的数据库管理系统,尤其适合...
标题"Spring+weblogic接收JMS消息"涉及到的核心知识点是Spring框架与WebLogic Server之间的整合,以及如何利用Spring来处理JMS消息。下面将详细讲解这两个方面的内容。 1. **Spring对JMS的支持**: - Spring通过`...
WebLogic JMS是Oracle WebLogic Server提供的消息中间件,它遵循JMS规范,用于在分布式环境中传递消息,实现应用程序间的异步通信。WebLogic JMS提供了消息生产者、消费者、队列和主题等概念,确保消息的可靠传输。 ...
6. **JNDI、JMS和JTA**:WebLogic Server提供了这些Java EE标准服务,用于实现应用的分布式和事务处理。 7. **安全管理**:包括用户、角色、权限的设置,以及SSL/TLS的配置,以确保应用服务的安全性。 8. **监控与...
本话题主要探讨如何在Spring框架下与WebLogic 9.2集成,实现JMS(Java Message Service)消息的发送。 首先,JMS是一种标准的API,用于在分布式环境中传递消息。通过JMS,应用可以在异步和解耦的方式下进行通信,...
【WebLogic 与 JMS+Spring 整合详解】 WebLogic 是由 BEA Systems(现已被 Oracle 收购)开发的一款 Java 应用服务器,它主要用于构建、部署和管理大型分布式Web应用、网络应用和数据库应用。WebLogic 提供了对多种...
WebLogic Server是一款由Oracle公司提供的企业级Java应用服务器,它提供了包括JMS(Java Message Service)在内的多种中间件服务。JMS是Java平台上的标准消息传递API,用于在分布式环境中发送和接收消息。配置...
6. **WebLogic与Oracle集成**:配置WebLogic连接到RAC数据库,设置数据源和JMS资源,确保Web应用程序能访问Oracle数据库。 7. **HACMP与WebLogic集成**:利用HACMP的资源管理功能,监控和管理WebLogic集群,确保在...
在“Linux+WebLogic+Oracle建站参考资料”中,你可能找到以下内容: 1. Linux系统管理指南:这可能包含如何安装和配置Linux系统,以及如何管理和维护Linux服务器的教程。 2. WebLogic部署手册:这部分资料可能会...
此外,MyEclipse还提供了对WebLogic集群、数据源、JMS队列等资源的管理功能,使得在WebLogic上的应用开发和维护更加便捷高效。 总结来说,"Myeclipse5.5 + Weblogic9.2 configure"主要涉及的是如何在MyEclipse 5.5...
**JMS技术综述** Java消息服务(Java Message Service,简称JMS)是一种标准的API,用于在分布式环境中实现应用程序间的异步通信。在企业级应用程序开发中,JMS解决了RMI-IIOP(远程方法调用-Internet Inter-ORB...
在实际部署中,还需要考虑网络配置、数据源、JMS队列、SSL证书、安全策略等多方面因素。同时,集群的健康检查、日志管理和性能监控也是运维中不可忽视的部分。一旦所有配置完成并通过测试,集群将提供高可用性和扩展...
作为Java EE(现在称为Jakarta EE)的一部分,WebLogic Server支持多种服务,包括Servlet、JSP、EJB、JMS、JCA、JNDI等。本手册将围绕WebLogic的核心功能、配置、管理和优化展开详细讨论。 一、WebLogic核心功能 1...
提供的文档"ejb3.0+Weblogic+Jboss安装配置及入门例子.doc"和"基于weblogic的EJB学习笔记.htm"应该包含详细的安装指南、配置步骤以及基础的EJB编程示例。"基于weblogic的EJB学习笔记-JSP编程-华夏名网资讯中心 虚拟...
- **目标**:学会如何在WebLogic Server中配置Java消息服务(JMS)。 - **内容**: - 创建JMS服务器。 - 配置JMS目标。 #### 练习11:配置SSL - **时间**:根据配置复杂度而定 - **目标**:了解如何在WebLogic ...
### Oracle WebLogic Server 10.3 指导手册核心知识点 #### 一、Oracle WebLogic Server 10.3 安装与配置 **重要性:**Oracle WebLogic Server 是一款先进的中间件平台,提供了强大的应用服务器功能,适用于构建、...
本人开发的spring jms项目,已经上线近一年了,这里是我项目jms配置文件,使用的是spring jms 整合weblogic jms。如果真的需要,请咨询我,并且附上我上传的这个配置文件,附近中没有带有这个文件,一律不作任何回答...
### 编程WebLogic JMS:深入理解与实践 #### 一、引言 随着企业级应用对消息处理的需求日益增长,Java消息服务(JMS)作为一种标准的消息中间件技术,已经成为开发分布式应用的重要组成部分。BEA WebLogic Server...
### JMS在WebLogic中的应用与部署 #### 引言 随着企业级应用程序对消息传递需求的日益增长,Java消息服务(JMS)作为一种标准的消息中间件接口,在处理分布式环境中不同组件之间的通信方面发挥着重要作用。BEA ...