`
xpenxpen
  • 浏览: 711069 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

集成Websphere Application Server 和Active MQ

    博客分类:
  • MQ
JMS 
阅读更多
本篇我们将不采用Tomcat,改用Websphere Application Server6.1, 但MQ仍采用ActiveMQ。
SpringJMS也不用了,收消息改用EJB2.0的MDB,发消息则自己连JNDI。

0. 准备工作:建Queue
0.1.在ActiveMQ里建2个队列ConsumerQueue和ReplyQueue



Q: 如何连接Websphere 和ActiveMQ?
A: Active MQ 是一个 JMS provider, 一般我们通过 Java EE Connector architecture(JCA) 来集成 JMS provider, 我们通过 Active MQ 提供的 resource adapter 来访问 Active MQ 服务器


1.安装 Adapter

1.1. 登录 WAS console
1.2. 访问 Resources->Resource Adapters->Resource adapters



1.3. 点击 Install RAR, 选择某个 node, 在 ACTIVEMQ_HOME\lib\optional 下可以找到 activemq-rar-5.4.1.rar,这是我们需要安装的 adapter:



1.4. 点击 Next,配置参数



1.5. 查看 Custom Properties, 其中 ServerUrl 应配置成指向已经安装的 Active MQ server




2.配置 J2C connection factories
2.1. 访问 Resources->Resource Adapters->J2C connection factories
2.2. 点击New
2.3. 连接工厂的名字输入MessageQueueCF, 类型选择javax.jms.QueueConnectionFactory



2.4.点击OK


3.配置 J2C activation specifications
3.1. 访问 Resources->Resource Adapters->J2C activation specifications
3.2. 点击New
3.3. 名字输入ConsumerQueueActivationSpec



3.4.点击OK
3.5.再次进入刚配置的activationSpec,点击右侧J2C activation specification custom properties



3.6.destination 改为ConsumerQueue ,destinationType 改为javax.jms.Queue



3.7.点击上方的save




4.配置 J2C administered objects
4.1. 访问 Resources->Resource Adapters->J2C administered objects
4.2. 点击New
4.3. 名字输入ConsumerQueue ,Administered object class选择ActiveMQQueue



4.4.点击OK
4.5.再次进入刚配置的Administered object,点击右侧J2C administered objects custom properties
4.6.PhysicalName 改为ConsumerQueue



4.7.点击上方的save

同样的步骤再配一个ReplyQueue


5.建工程
5.1.打开我们的RAD,新建一个EJB Project,工程名字JMSTest,
5.2.再新建一个Enterprise Application Project,工程名字JMSTestEAR,JavaEE Module Dependencies选中刚刚建的工程JMSTest
5.3.在JMSTest工程里新建一个java类,QueueConsumerMDBBean,这个类采用EJB2.0的MDB方式监听ConsumerQueue消息,
收到消息后,我们打印了消息到控制台,然后自己用JNDI查找另外一个ReplyQueue,把此消息转发给那个Queue
package ejbs;

import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
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.InitialContext;
import javax.naming.NamingException;

public class QueueConsumerMDBBean implements MessageDrivenBean, MessageListener {
	
	private static final String ENV_JNDI_REPLY_QUEUE_CON_FACTORY = "java:comp/env/MessageQueueCF";
	private static final String ENV_JNDI_REPLY_QUEUE = "java:comp/env/ReplyQueue";
	
	private MessageDrivenContext messageDrivenCtx;
	
	public MessageDrivenContext getMessageDrivenContext() {
		return messageDrivenCtx;
	}
	public void setMessageDrivenContext(MessageDrivenContext ctx) {
		messageDrivenCtx = ctx;
	}
	public void ejbCreate() {
	}
	public void ejbRemove() {
	}
	
	/**
	 * onMessage
	 */
	public void onMessage(Message msg) {
		if (!(msg instanceof TextMessage)) {
			throw new IllegalArgumentException("Message type is not text message!");
		}
		
		try {
		
			TextMessage textMessage = (TextMessage) msg;
			System.out.println("Receive message:" + textMessage.getText());
		
			InitialContext initContext = new InitialContext();
			QueueConnectionFactory replyQueueConnectionFactory = (QueueConnectionFactory) initContext.lookup(ENV_JNDI_REPLY_QUEUE_CON_FACTORY);
			Queue replyQueue = (Queue) initContext.lookup(ENV_JNDI_REPLY_QUEUE);
			
			QueueConnection queueConnection = replyQueueConnectionFactory.createQueueConnection();
			queueConnection.start();
			QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
			QueueSender queueSender = queueSession.createSender(replyQueue);
			TextMessage outMessage = queueSession.createTextMessage(textMessage.getText());
			queueSender.send(outMessage);
			
		} catch (NamingException e) {
			throw new RuntimeException(e);
		} catch (JMSException e) {
			throw new RuntimeException(e);
		}
	}
	
}



6.配置ejb-jar.xml
6.1.双击打开JMSTest工程里的ejb-jar.xml
6.2.选择bean选项卡
6.3.点击Add…
6.4.选择Message-driven Bean, Bean name输入QueueConsumerMDB,



6.5.JMS type选择MessageListener



6.6.Transaction type选择Bean



6.7.完成以后,在右侧Destination type选择Queue,Websphere bindings选择JCA adapter,ActivationSpec JNDI Name输入ConsumerQueueActivationSpec,Destination JNDI name输入ConsumerQueue



6.8.选择References选项卡
6.9.选中QueueConsumerMDB,点击Add…
6.10.选择resource reference



6.11.名字输入MessageQueueCF,Type选择javax.jms.QueueConnectionFactory,Authentication选择Application,Sharing scope选择shareable



6.12.完成以后,在右侧JNDI Name输入MessageQueueCF



6.13.选中QueueConsumerMDB,点击Add…
6.14.选择resource reference
6.15.名字输入ReplyQueue,Type选择javax.jms.Queue,Authentication选择Application,Sharing scope选择shareable



6.16.完成以后,在右侧JNDI Name输入ReplyQueue



6.17.最后不要忘了保存ejb-jar.xml

7.测试

7.1.打开ActiveMQ图形化管理界面,点击ConsumerQueue右边的"Send To",输入消息,点击Send



7.2.可在控制台看到打印的消息,证明MDB已经接收到消息



7.3.并且可以看到ReplyQueue里接受到一条消息,一层层点进去,确认一下果然是那句消息,证明发送消息也成功了。







最后附上RAD工程文件
  • 大小: 60.5 KB
  • 大小: 34.2 KB
  • 大小: 27.8 KB
  • 大小: 47.1 KB
  • 大小: 9.3 KB
  • 大小: 21.1 KB
  • 大小: 13.1 KB
  • 大小: 5.9 KB
  • 大小: 39.3 KB
  • 大小: 18.1 KB
  • 大小: 25.6 KB
  • 大小: 5.9 KB
  • 大小: 45.1 KB
  • 大小: 32.1 KB
  • 大小: 63.8 KB
  • 大小: 43.2 KB
  • 大小: 39.3 KB
  • 大小: 39.9 KB
  • 大小: 29 KB
  • 大小: 38.5 KB
  • 大小: 24.7 KB
  • 大小: 57.2 KB
  • 大小: 25.1 KB
  • 大小: 9.3 KB
  • 大小: 13.1 KB
  • 大小: 2.8 KB
分享到:
评论

相关推荐

    WebSphere Application Server V6.1 Security Handbook.

    该文档详细介绍了如何配置和管理WebSphere Application Server的安全特性,包括用户注册表的设置、管理安全性配置以及如何集成第三方安全组件等内容。 #### 二、重点章节分析 ##### 第1章:介绍 本章主要介绍了...

    Websphere Application Server 6.0 应用指南

    - IBM Rational Web Developer for WebSphere Software 是一款专注于Web应用开发的集成开发环境(IDE),它支持WebSphere Application Server 6.0,提供了强大的开发工具,包括代码编辑器、调试器以及一系列的开发...

    Websphere Application Server 6.0配置与管理

    其中,Websphere 系列主要服务于电子商务领域,旨在为企业提供一个强大的电子商务平台,支持应用程序的开发、部署和集成。WebSphere Application Server 作为 WebSphere 家族的一员,位于软件平台的基础层...

    W38S1 Administration of WebSphere Application Server V5.pdf

    4. **应用程序部署**:讲解如何部署应用程序到 WebSphere Application Server,包括部署策略、资源管理和性能调优等。 5. **集群配置与管理**:介绍集群的概念及其在高可用性和负载均衡方面的作用,包括集群的设置和...

    WebSphere Application Server V6

    WebSphere Application Server V6的自动安装功能极大地简化了应用部署的过程,提高了开发效率和运维便利性。通过合理配置快速部署工具和正确管理监视目录,可以实现应用的无缝部署与更新。掌握这些技巧,能够帮助...

    WebSphere Application Server 启动错误诊断(WAS)

    WebSphere Application Server 启动错误诊断 在本文中,我们将详细介绍 WebSphere Application Server(WAS)启动错误的诊断方法。WAS 是一个复杂的应用服务器,启动过程中可能会出现各种错误,影响服务器的正常...

    WebSphere Application Server9.0.0.2.txt

    WebSphere Application Server9.0.0.2 安装包百度云盘资源地址,非商业用途,仅供学习使用。

    WebSphere Application Server集群和架构FAQ

    WebSphere Application Server集群和架构FAQ

    WebSphere Application Server V6 Handbook

    - **2.3.4 外部服务器**:不是 WebSphere Application Server 的一部分,但可以通过适配器或连接器与之集成。 **2.4 容器** - **2.4.1 Web 容器**:支持 Web 应用程序的部署和执行,处理 HTTP 请求。 - **2.4.2 ...

    WebSphere Application Server for Developers V7

    IBM WebSphere Application Server (WAS) 是一款高性能的企业级应用服务器,适用于构建、部署和管理企业级Java应用程序。本指南旨在帮助开发者全面了解WebSphere Application Server V7,并提供详细的步骤来创建、...

    WebSphere Application Server 常见问题及解答:开发与部署.doc

    Application Server Toolkit(AST)是 WebSphere Application Server V6.1 的一个组件,提供了基本的开发和运行支持。AST 包括了各种向导和工具,用于创建新的 Web 应用程序、Web 服务、Portlet 和 EJB 组件。AST 还...

    WebSphere Application Server文档

    在本文中,我们将深入探讨WebSphere Application Server的关键概念、功能以及如何进行配置和管理。 一、WebSphere Application Server概述 WebSphere Application Server作为IBM的旗舰产品,它支持多种服务,包括...

    IBM WebSphere Application Server Win64位

    IBM WebSphere Application ...总的来说,IBM WebSphere Application Server是企业级Java应用的强大支撑平台,其安装和配置过程需要一定的技术知识,但通过深入理解和实践,可以充分利用其功能来支持复杂的企业业务。

    WebSphere Application Server V6 Security Handbook

    通过上述介绍可以看出,《WebSphere Application Server V6 安全手册》详细地讲解了如何配置和管理 WebSphere Application Server 的安全特性。从用户注册表的配置到全局安全的启用,每一项都对确保应用服务器的安全...

    WebSphere Application Server V8.5 Administration and Configuration Guide

    WebSphere Application Server V8.5是IBM推出的一款应用服务器产品,它允许企业构建、部署和运行高性能的企业Java应用。该版本包括多个配置文件,其中Full Profile针对完整的企业级应用部署而设计。它提供了全面的...

    IBM 红皮书 WAS WebSphere Application Server

    《IBM 红皮书 WAS WebSphere Application Server Liberty Profile Guide for Developers》是针对开发者的一份详细指南,旨在帮助他们理解并有效地使用WebSphere Application Server (WAS) 的Liberty Profile。...

    Websphere Application Server 6.1配置JDBC数据源.doc

    请注意,不同版本的WebSphere Application Server可能有一些细微的配置差异,但基本流程和概念是相同的。在实际操作中,务必参考官方文档或在线帮助,以获取最准确的配置指南。此外,为了保证系统的安全,建议定期...

    IBM redbook Experience Java EE! Using WebSphere Application Server Community Edition

    Using WebSphere Application Server Community Edition》是一本专注于Java企业版(Java EE)开发和WebSphere应用服务器社区版使用的专业指南。这本书深入浅出地介绍了如何利用IBM的开源应用服务器平台来构建高效、...

Global site tag (gtag.js) - Google Analytics