如何让jboss下的消息驱动bean消费远程JMS消息

用消息驱动bean来处理本地的JMS消息太容易不过了,但是如何处理远程的消息呢?翻遍了Java EE手册和API也找不到。原来各种应用服务器都有各自的实现。那么如何让jboss下的消息驱动bean消费远程JMS消息呢?把下面的代码复制到一个文件里,并重名为以-service.xml结尾的文件,放到jboss的deploy目录,就可以在本地得到一个从远程获取消息的JMS provider。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
     < mbean code = "org.jboss.jms.jndi.JMSProviderLoader"
name = "jboss.mq:service=JMSProviderLoader,name=RemoteJMSProvider,server=remotehost" >
         < attribute name = "ProviderName" >RemoteJMSProvider</ attribute >
         < attribute name = "ProviderAdapterClass" >org.jboss.jms.jndi.JNDIProviderAdapter</ attribute >
         <!-- The connection factory -->
         < attribute name = "FactoryRef" >UIL2XAConnectionFactory</ attribute >
         <!-- The queue connection factory -->
         < attribute name = "QueueFactoryRef" >UIL2XAConnectionFactory</ attribute >
         <!-- The topic factory -->
         < attribute name = "TopicFactoryRef" >UIL2XAConnectionFactory</ attribute >
         <!-- Connect to JNDI on the host "the-remote-host-name" 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=the-remote-host-name:1099
         </ attribute >
     </ mbean >



注意,你要把上面的 the-remote-host-name 改成你的。部署完成后,确认在jboss的JndiViewer里能不能看到 java:/RemoteJMSProvider 。然后再MDB类上加上:

1
2
3
4
5
6
7
8
@MessageDriven (activateConfig = {
     @ActivationConfigProperty (propertyName= "destinationType" , propertyValue= "javax.jms.Queue" ),
     @ActivationConfigProperty (propertyName= "destination" , propertyValue= "queue/testQueue" ),
     @ActivationConfigProperty (propertyName= "providerAdapterJNDI" , propertyValue= "java:/RemoteJMSProvider" )
})
public class MDB implements MessageListener {
     ...
}



providerAdapterJNDI属性使这个MDB从刚才部署好的JMS provider那里读取消息。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值