在JBOSS中开发SESSIONBEAN和MSGBEAN

JBOSS中开发SESSIONBEANMSGBEAN

 

做法:

JBOSS中,JMS连接工厂的JNDI名:

private static final java.lang.String DESTINATION_JNDI_NAME="queue/testQueue";

private static final java.lang.String CONNECTION_FACTORY_JNDI_NAME="java:JmsXA";

 

Queue q = MsbUtil.getQueue();

QueueConnection conn = MsbUtil.getQueueConnection();

Session ssion = conn.createQueueSession(true,1);

TextMessage msg = ssion.createTextMessage(str);

MessageProducer proc = ssion.createProducer(q);

proc.send(msg);

ssion.close();

 

public static javax.jms.Queue getQueue() throws javax.naming.NamingException

   {

      if (cachedQueue == null) {

         // Obtain initial context

         javax.naming.InitialContext initialContext = new javax.naming.InitialContext();

         try {

            java.lang.Object objRef = initialContext.lookup(DESTINATION_JNDI_NAME);

            cachedQueue = (javax.jms.Queue) objRef;

         } finally {

            initialContext.close();

         }

      }

      return cachedQueue;

   }

 

 

public static javax.jms.QueueConnection getQueueConnection() throws javax.naming.NamingException, javax.jms.JMSException

   {

       

       //SpyConnectionFactory conn = new SpyConnectionFactory();

      if (cachedConnectionFactory == null) {

         // Obtain initial context

         javax.naming.InitialContext initialContext = new javax.naming.InitialContext();

         try {

            java.lang.Object objRef = initialContext.lookup(CONNECTION_FACTORY_JNDI_NAME);

            cachedConnectionFactory = (javax.jms.QueueConnectionFactory) objRef;

         } finally {

            initialContext.close();

         }

      }

      return cachedConnectionFactory.createQueueConnection();

   }

 

 

MDB配置:

Ebj-jar.xml

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

 

<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

 

<ejb-jar >

 

   <description><![CDATA[No Description.]]></description>

   <display-name>Generated by XDoclet</display-name>

 

   <enterprise-beans>

 

      <!-- Session Beans -->

     <!--

       To add session beans that you have deployment descriptor info for, add

       a file to your XDoclet merge directory called session-beans.xml that contains

       the <session></session> markup for those beans.

     -->

 

      <!-- Entity Beans -->

     <!--

       To add entity beans that you have deployment descriptor info for, add

       a file to your XDoclet merge directory called entity-beans.xml that contains

       the <entity></entity> markup for those beans.

     -->

 

      <!-- Message Driven Beans -->

      <message-driven >

         <description><![CDATA[Msb]]></description>

         <display-name>MsgBean</display-name>

         <ejb-name>MsgBean</ejb-name>

         <ejb-class>com.mudboy.msg.ejb.MsbBean</ejb-class>

         <transaction-type>Container</transaction-type>

         <acknowledge-mode>Auto-acknowledge</acknowledge-mode>

         <message-driven-destination>

            <destination-type>javax.jms.Queue</destination-type>

         </message-driven-destination>

      </message-driven>

 

     <!--

       To add message driven beans that you have deployment descriptor info for, add

       a file to your XDoclet merge directory called message-driven-beans.xml that contains

       the <message-driven></message-driven> markup for those beans.

     -->

 

   </enterprise-beans>

 

   <!-- Relationships -->

 

   <!-- Assembly Descriptor -->

     <!--

       To specify your own assembly descriptor info here, add a file to your

       XDoclet merge directory called assembly-descriptor.xml that contains

       the <assembly-descriptor></assembly-descriptor> markup.

     -->

 

   <assembly-descriptor >

     <!--

       To specify additional security-role elements, add a file in the merge

       directory called ejb-security-roles.xml that contains them.

     -->

 

   <!-- method permissions -->

     <!--

       To specify additional method-permission elements, add a file in the merge

       directory called ejb-method-permissions.ent that contains them.

     -->

 

   <!-- finder permissions -->

 

   <!-- transactions -->

     <!--

       To specify additional container-transaction elements, add a file in the merge

       directory called ejb-container-transaction.ent that contains them.

     -->

 

   <!-- finder transactions -->

 

     <!--

       To specify an exclude-list element, add a file in the merge directory

       called ejb-exclude-list.xml that contains it.

     -->

   </assembly-descriptor>

 

</ejb-jar>

 

Jboss.xml

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

<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" "http://www.jboss.org/j2ee/dtd/jboss_3_2.dtd">

<jboss>

  <enterprise-beans>

    <message-driven>

      <ejb-name>MsgBean</ejb-name>

      <destination-jndi-name>queue/testQueue</destination-jndi-name>

      <configuration-name>Standard Message Driven Bean</configuration-name>

    </message-driven>

  </enterprise-beans>

</jboss>

 

 

MyEclipse开发还是很容易的。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值