在JBOSS中开发SESSIONBEAN和MSGBEAN
在JBOSS中開發SESSIONBEAN和MSGBEAN
?
做法:
在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開發還是很容易的。
?
總結
以上是生活随笔為你收集整理的在JBOSS中开发SESSIONBEAN和MSGBEAN的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 0610
- 下一篇: 有关JNLP中传SESSIONID为参数