设为首页 收藏本站
查看: 974|回复: 0

[经验分享] 如何在 JBoss 里配置 IBM MQ

[复制链接]

尚未签到

发表于 2015-10-4 09:56:55 | 显示全部楼层 |阅读模式
  在本文中,我将告诉大家如何在JBoss里安装、配置WebSphere MQ资源适配器。
  安装WebSphere MQ资源适配器:   
从安装目录复制wmq.jmsra.rar文件到服务器的部署目录中,例如:<安装路径>/server/default/deploy。此时资源适配器将会自动选择服务器。
  安装WebSphere MQ扩展事务客户端:   
WebSphere MQ扩展事务客户端允许你使用XA分布式事务,并用客户端模式连接到WebSphere MQ队列管理器。要将客户端安装在JBoss,需要从安装目录复制com.ibm.mqetclient.jar文件到服务器的lib目录中,例如<安装路径>/server/default/lib。
  为你的应用程序配置资源适配器:   
WebSphere MQ资源适配器允许你定义一些全局的属性。在JBoss中JCA出站流的资源定义在-ds.xml文件,名为wmq.jmsra-ds.xml。
此文件的概要如下:



1<?xml version="1.0" encoding="UTF-8"?>

2<connection-factories>

3  <!-- mbeans defining JCA administered objects -->

4  <mbean/>

5  <!-- JCA Connection factory definitions -->

6  <tx-connection-factory/>

7</connection-factories>
  从上可以看出JCA连接工厂的定义在<tx-connection-factory>元素,而且JMS队列和主题被定义在JCA的管理对象mbean里面。
  简单的两个队列-入站和出站的完整示例如下:



01<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

02<connection-factories>

03    <tx-connection-factory>

04        <jndi-name>jms/MyAppConnectionFactory</jndi-name>

05        <rar-name>wmq.jmsra.rar</rar-name>

06        <use-java-context>true</use-java-context>

07        <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>

08        <min-pool-size>8</min-pool-size>

09        <max-pool-size>36</max-pool-size>

10        <config-property type="java.lang.String" name="channel">${channel}</config-property>

11        <config-property type="java.lang.String" name="hostName">${hostName}</config-property>

12        <config-property type="java.lang.String" name="port">1414</config-property>

13        <config-property type="java.lang.String"name="queueManager">${queueManager}</config-property>

14        <config-property type="java.lang.String"name="transportType">CLIENT</config-property>

15        <config-property type="java.lang.String" name="username">munish</config-property>

16        <security-domain-and-application>JmsXARealm</security-domain-and-application>

17        <xa-transaction/>

18    </tx-connection-factory>

19    <mbean name="imq.queue:name=MY.APP.INBOUND.QUEUE"code="org.jboss.resource.deployment.AdminObject" >

20  <attribute name="JNDIName">jms/IncomingQueue</attribute>

21  <depends optional-attribute-name="RARName">jboss.jca:name='wmq.jmsra.rar',service=RARDeployment</depends>

22  <attribute name="Type">javax.jms.Queue</attribute>

23  <attribute name="Properties">

24   baseQueueManagerName=${queueManager}

25   baseQueueName=MY.APP.INBOUND.QUEUE

26    </attribute>

27    </mbean>

28    <mbean name="imq.queue:name=MY.APP.OUTBOUND.QUEUE"code="org.jboss.resource.deployment.AdminObject">

29        <attribute name="JNDIName">jms/OutgoingQueue</attribute>

30        <depends optional-attribute-name="RARName">jboss.jca:name='wmq.jmsra.rar',service=RARDeployment</depends>

31        <attribute name="Type">javax.jms.Queue</attribute>

32        <attribute name="Properties">

33            baseQueueManagerName=${queueManager}

34            baseQueueName=MY.APP.OUTBOUND.QUEUE

35        </attribute>

36    </mbean>

37</connection-factories>
  在JBoss启动脚本中占位符属性被定义为:
-Dchannel=MQTEST -DhostName=localhost -DqueueManager=TST_MGR
  配置入站消息传递:
消息传递配置在jboss.xml文件中,这个文件的内容会有所不同,但大致如下:
jboss.xml



01<jboss xmlns="http://www.jboss.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

02 xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee

03 http://www.jboss.org/j2ee/schema/jboss_5_0.xsd" version="5.0">

04 <enterprise-beans>

05  <message-driven>

06   <ejb-name>MyMessageBean</ejb-name>

07    <!--  Make sure following System properties are defined in JBoss before deploying the application   -->

08     <activation-config>

09                     <activation-config-property>

10                             <activation-config-property-name>DestinationType</activation-config-property-name>

11                             <activation-config-property-value>javax.jms.Queue</activation-config-property-value>

12                     </activation-config-property>

13                     <activation-config-property>

14                             <activation-config-property-name>destination</activation-config-property-name>

15                             <activation-config-property-value>MY.APP.INBOUND.QUEUE</activation-config-property-value>

16                     </activation-config-property>

17                     <activation-config-property>

18                             <activation-config-property-name>channel</activation-config-property-name>

19                             <activation-config-property-value>${channel}</activation-config-property-value>

20                     </activation-config-property>

21                     <activation-config-property>

22                             <activation-config-property-name>hostName</activation-config-property-name>

23                             <activation-config-property-value>${hostName}</activation-config-property-value>

24                     </activation-config-property>

25                     <activation-config-property>

26                             <activation-config-property-name>port</activation-config-property-name>

27                             <activation-config-property-value>1414</activation-config-property-value>

28                     </activation-config-property>

29                     <activation-config-property>

30                             <activation-config-property-name>queueManager</activation-config-property-name>

31                             <activation-config-property-value>${queueManager}</activation-config-property-value>

32                     </activation-config-property>

33                     <activation-config-property>

34                             <activation-config-property-name>transportType</activation-config-property-name>

35                             <activation-config-property-value>CLIENT</activation-config-property-value>

36                     </activation-config-property>

37                     <activation-config-property>

38                             <activation-config-property-name>username</activation-config-property-name>

39                             <activation-config-property-value>munish</activation-config-property-value>

40                     </activation-config-property>

41              </activation-config>

42               <!-- instruct the MDB to use the WebSphere MQ resource adapter -->

43           <resource-adapter-name>wmq.jmsra.rar</resource-adapter-name>

44     </message-driven>

45 </enterprise-beans>

46</jboss>
  必须指定目标类型和名称属性。其他属性都是可选的,如果省略,将使用其默认值。
  一个简单的MDB定义入站消息如下所示:



01/**

02 * This message driven bean is used to collect asynchronously received messages.

03 *

04 * <a href="http://my.oschina.net/arthor" class="referer" target="_blank">@author</a>  Munish Gogna

05 */

06@MessageDriven(mappedName = "jms/IncomingQueue")

07public final class MyMessageBean implements javax.jms.MessageListener {

08  private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(MyMessageBean.class);

09  public void onMessage(final javax.jms.Message message) {

10    LOGGER.info("Received message: " + message);

11    // TODO - do processing with the message here

12  }

13}
  一个简单的java类发送消息到输出队列如下所示:



01/**

02 * This class is used to send text messages to a queue.

03 *

04 * <a href="http://my.oschina.net/arthor" class="referer" target="_blank">@author</a>  Munish Gogna

05 */

06public final class MessageSender {

07  private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger.getLogger(MessageSender.class);

08  /**

09   * A coarse-grained method, nothing fancy. In actual applications please re factor the code and

10   * handle the exceptions properly.

11   *

12   * @throws Exception

13   */

14  public void send(final String message) throws Exception {

15    if (message == null) {

16      throw new IllegalArgumentException("Parameter message cannot be null");

17    }

18    javax.jms.QueueConnection connection = null;

19    javax.jms.Session session = null;

20    try {

21      javax.naming.Context fContext = new javax.naming.InitialContext();

22      javax.jms.QueueConnectionFactory fConnectionFactory = (javax.jms.QueueConnectionFactory) fContext

23          .lookup("java:jms/MyAppConnectionFactory");

24      connection = fConnectionFactory.createQueueConnection();

25      session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

26      final javax.naming.Context jndiContext = newjavax.naming.InitialContext();

27      final javax.jms.Destination destination = (javax.jms.Destination) jndiContext.lookup("jms/OutgoingQueue");

28      final javax.jms.MessageProducer messageProducer = session.createProducer(destination);

29      final javax.jms.TextMessage textMessage = session.createTextMessage(message);

30      messageProducer.send(textMessage);

31      messageProducer.close();

32    } catch (Exception nex) {

33      throw nex;

34    } finally {

35      if (session != null) {

36        try {

37          session.close();

38        } catch (JMSException e) {

39          LOGGER.error("Failed to close JMS session", e);

40        }

41      }

42      if (connection != null) {

43        try {

44          connection.close();

45        } catch (JMSException e) {

46          LOGGER.error("Failed to close JMS connection", e);

47        }

48      }

49    }

50  }

51}
  最终RFHUTILC.EXE可用于连接到远程队列
  原文地址:http://www.oschina.net/question/157182_58109

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-122434-1-1.html 上篇帖子: 谁能成为互联网上的IBM(摘自:IT经理世界;作者:杜晨,周源) 下篇帖子: IBM Tivoli Directory Server 6.3 System Administration
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表