jboss jms配置

 

参见文档:http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/userguide-1.4.2.GA/html/index.html
http://www.jboss.org/file-access/default/members/jbossas/freezone/docs/Server_Configuration_Guide/4/html/index.html

O'Relly 中 EJB3中的:

Almost anything that can be done with the pub/sub model can be done with point-to-point, and vice versa. An analogy can be drawn to developers' programming language preferences. In theory, any application that can be written with Pascal can also be written with C. Anything that can be written in C++ can also be written in Java. In some cases, it comes down to a matter of preference, or which model you are already familiar with.

In most cases, the decision about which model to use depends on which model is a better fit for the application. With pub/sub, any number of subscribers can be listening on a topic, and all of them will receive copies of the same message. The publisher may not care if everybody is listening, or even if nobody is listening. For example, consider a publisher that broadcasts stock quotes. If any particular subscriber is not currently connected and misses out on a great quote, the publisher is not concerned. In contrast, a point-to-point session is likely to be intended for a one-on-one conversation with a specific application at the other end. In this scenario, every message really matters. The range and variety of the data the messages represent can be a factor as well. Using pub/sub, messages are dispatched to the consumers based on filtering that is provided through the use of specific topics. Even when messaging is being used to establish a one-on-one conversation with another known application, it can be advantageous to use pub/sub with multiple topics to segregate different kinds of messages. Each kind of message can be dealt with separately through its own unique consumer and onMessage( ) listener.

Point-to-point is more convenient when you want a particular receiver to process a given message once. This is perhaps the most critical difference between the two models: p2p guarantees that only one consumer processes each message. This ability is extremely important when messages need to be processed separately but in tandem.

publish/subscriber 是推送,当时没接到的就再接不到了(durable除外)
p2p是poll, 总是保证有一个接收者接收到了。

配置topic,以-service.xml结尾的xml文件或直接在%jboss_home%\server\default\deploy\jms\jbossmq-destinations-service.xml中配置。
<?xml version="1.0" encoding="UTF-8"?>
<server>
  <!-- Destination without a configured SecurityManager or without a
       a SecurityConf will default to role guest with read=true, write=true,
       create=false.
  -->
  <mbean code="org.jboss.mq.server.jmx.Topic"
     name="jboss.mq.destination:service=Topic,name=myTestTopic">
    <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
    <depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>         
    <attribute name="JNDIName">jms/test/testT</attribute>   <!-- 如果这里没配置,则默认的是topic/myTestTopic(对于queue则是queue/queue名) -->
  </mbean>   
</server>

ConnectionFactory的配置:%jboss_home%\server\default\deploy\jms\uil2-service.xml
jboss默认的factory分别是
Queue:QueueConnectionFactory
Topic:TopicConnectionFactory
像上面的myTestTopic则应该在TopicConnectionFactory中查找。
关于自定义factory还没弄明白!

下面引用自http://blog.csdn.net/jiulong/archive/2006/08/21/1101385.aspx

在jboss 4中,如果一个appserver A中的消息驱动bean需要访问另外一个appserver B中的消息队列,需要对A及其bean部署文件做相应的配置;对于消息服务器B无需做改动。
对A大致要做3件事情。
1、修改jboss安装目录的jboss-4.0.2\server\default\deploy\jms的jms-ds.xml文件,用红色部分替换掉灰色部分。这里实际上是重新配置了我们如何去访问远程jndi服务器绑定的对象。
 
<?xml version="1.0" encoding="UTF-8"?>
 
<connection-factories>
 
<!-- ==================================================================== -->
<!-- JMS Stuff                                                            -->
<!-- ==================================================================== -->
 
<!-- The JMS provider loader -->
<mbean code="org.jboss.jms.jndi.JMSProviderLoader"
         name="jboss.mq:service=JMSProviderLoader,name=JMSProvider">
    <attribute name="ProviderName">DefaultJMSProvider</attribute>
    <attribute name="ProviderAdapterClass">
      org.jboss.jms.jndi.JNDIProviderAdapter
    </attribute>
    <!-- The combined connection factory -->
    <attribute name="FactoryRef">java:/XAConnectionFactory</attribute>
    <!-- The queue connection factory -->
    <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
    <!-- The topic factory -->
    <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
    <!-- Uncomment to use HAJNDI to access JMS
    <attribute name="Properties">
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
       java.naming.provider.url=localhost:1100
    </attribute>
    -->
</mbean>
 
 
 <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
         name="jboss.mq:service=JMSProviderLoader,name=RemoteJMSProvider,server=192.168.0.92">
    <attribute name="ProviderName">QueuehostJMSProvider</attribute>
    <attribute name="ProviderAdapterClass">org.jboss.jms.jndi.JNDIProviderAdapter</attribute>
    <!-- The queue connection factory -->
    <attribute name="QueueFactoryRef">XAConnectionFactory</attribute>
    <!-- The topic factory -->
    <attribute name="TopicFactoryRef">XAConnectionFactory</attribute>
    <!-- Connect to JNDI on the host "queuehost" port 1099-->
    <attribute name="Properties">
       java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
       java.naming.factory.url.pkgs=org.jnp.interfaces
       java.naming.provider.url=192.168.0.92:1099
    </attribute>
</mbean>
 
 
<!-- The server session pool for Message Driven Beans -->
<mbean code="org.jboss.jms.asf.ServerSessionPoolLoader"
         name="jboss.mq:service=ServerSessionPoolMBean,name=StdJMSPool">
    <depends optional-attribute-name="XidFactory">jboss:service=XidFactory</depends>
    <attribute name="PoolName">StdJMSPool</attribute>
    <attribute name="PoolFactoryClass">
      org.jboss.jms.asf.StdServerSessionPoolFactory
    </attribute>
</mbean>
 
<!-- JMS XA Resource adapter, use this to get transacted JMS in beans -->
<tx-connection-factory>
    <jndi-name>JmsXA</jndi-name>
    <xa-transaction/>
    <rar-name>jms-ra.rar</rar-name>
    <connection-definition>org.jboss.resource.adapter.jms.JmsConnectionFactory</connection-definition>
    <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Topic</config-property>
    <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/DefaultJMSProvider</config-property>
    <max-pool-size>20</max-pool-size>
    <security-domain-and-application>JmsXARealm</security-domain-and-application>
</tx-connection-factory>
 
</connection-factories>
 
2、在消息驱动Bean所在的ejb.jar文件的jboss.xml部署描述符文件中加入如下代码.
 
<jboss>
 
   <invoker-proxy-bindings>
      <invoker-proxy-binding>
         <name>lottery-mdb-invoker</name>
         <invoker-mbean>does-not-matter</invoker-mbean>
         <proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
         <proxy-factory-config>
            <JMSProviderAdapterJNDI>QueuehostJMSProvider</JMSProviderAdapterJNDI>
            <ServerSessionPoolFactoryJNDI>StdJMSPool</ServerSessionPoolFactoryJNDI>
            <MinimumSize>1</MinimumSize>
            <KeepAliveMillis>30000</KeepAliveMillis>
            <MaximumSize>15</MaximumSize>
            <MaxMessages>1</MaxMessages>
            <MDBConfig>
               <ReconnectIntervalSec>10</ReconnectIntervalSec>
               <DLQConfig>
                  <DestinationQueue>queue/DLQ</DestinationQueue>
                  <MaxTimesRedelivered>10</MaxTimesRedelivered>
                  <TimeToLive>0</TimeToLive>
               </DLQConfig>
            </MDBConfig>
         </proxy-factory-config>
      </invoker-proxy-binding>
   </invoker-proxy-bindings>
 
</jboss>
 
 
3、在mdbean配置部分加上如下红色部分语句。
<invoker-proxy-binding-name>lottery-mdb-invoker</invoker-proxy-binding-name>这个名字需要与上边第二步配置的完全匹配。
 
<jboss>
    
  <enterprise-beans>
 
    <message-driven>         
      <ejb-name>RecieveMdBean</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/lotappQueue</destination-jndi-name>
         <invoker-bindings>
            <invoker>                     <invoker-proxy-binding-name>lottery-mdb-invoker</invoker-proxy-binding-name>
            </invoker>
         </invoker-bindings>
        </message-driven>
   
    </enterprise-beans>
</jboss>
 
 
Ok,我们完整的jboss.xml文件内容如下:
 
<jboss>
 
   <invoker-proxy-bindings>
      <invoker-proxy-binding>
         <name>lottery-mdb-invoker</name>
         <invoker-mbean>does-not-matter</invoker-mbean>
         <proxy-factory>org.jboss.ejb.plugins.jms.JMSContainerInvoker</proxy-factory>
         <proxy-factory-config>
            <JMSProviderAdapterJNDI>QueuehostJMSProvider</JMSProviderAdapterJNDI>
            <ServerSessionPoolFactoryJNDI>StdJMSPool</ServerSessionPoolFactoryJNDI>
            <MinimumSize>1</MinimumSize>
            <KeepAliveMillis>30000</KeepAliveMillis>
            <MaximumSize>15</MaximumSize>
            <MaxMessages>1</MaxMessages>
            <MDBConfig>
               <ReconnectIntervalSec>10</ReconnectIntervalSec>
               <DLQConfig>
                  <DestinationQueue>queue/DLQ</DestinationQueue>
                  <MaxTimesRedelivered>10</MaxTimesRedelivered>
                  <TimeToLive>0</TimeToLive>
               </DLQConfig>
            </MDBConfig>
         </proxy-factory-config>
      </invoker-proxy-binding>
   </invoker-proxy-bindings>   
 
  <enterprise-beans>
 
    <message-driven>         
      <ejb-name>RecieveMdBean</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/lotappQueue</destination-jndi-name>
         <invoker-bindings>
            <invoker>     
               <invoker-proxy-binding-name>lottery-mdb-invoker</invoker-proxy-binding-name>
            </invoker>
         </invoker-bindings>
        </message-driven>
   
    </enterprise-beans>
</jboss>

Jboss控制台(WebConsole/J2EE Domains/JBoss management/j2ee resource/local jms/)下可以看到消息总数。


Total views.

© 2013 - 2024. All rights reserved.

Powered by Hydejack v6.6.1