在邮件配置MappedName注释驱动Bean动态 [英] Configuring MappedName annotation in Message Driven Bean dynamically

查看:305
本文介绍了在邮件配置MappedName注释驱动Bean动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用消息驱动Bean,从那里接收信息的目的地名称是标注硬codeD @MessageDriven(mappedName =someDestinationName)

有没有办法在运行时添加这些信息?贝娄是驱动的示例消息Bean类。

 包mdb.beans;进口javax.ejb.Activati​​onConfigProperty;
进口javax.ejb.MessageDriven;
进口javax.jms.Message;
进口一个javax.jms.MessageListener;@MessageDriven(mappedName =someDestinationName,activati​​onConfig =
{
    @Activati​​onConfigProperty(propertyName的=acknowledgeMode,为PropertyValue =自动应答),
    @Activati​​onConfigProperty(propertyName的=destinationType,为PropertyValue =的javax.jms.Queue)
})
公共类MDBSample实现消息监听
{
    公共MDBSample()
    {
        //构造
    }    @覆盖
    公共无效的onMessage(消息消息)
    {
        //收到消息时的逻辑
    }
}


解决方案

据我所知,没有,你不能这样做。

由于,目的地的连接(这是一个字符串)和bean(这是一个类)以编程方式完成的一次在部署时,则不能更改目的地。

也许有重新绑定一个黑客;我的意思是迫使容器释放MDB,然后更改目的地并重新initalize(通过依赖注入,再后建设步骤等),但我怀疑应用程序服务器将允许。

从JSR-318(EJB 3.1规范)摘录;


  

5.4.17协会的消息驱动Beanwith目的地或端点


  
  

一个消息驱动bean与当bean部署在容器中的目的地或端点关联。这是部署的责任推给消息驱动Bean与目标或端点关联。


  
  

5.4.17.1 JMS消息驱动Bean


  
  

一个JMS消息驱动bean与当bean部署在容器中的JMS目标(队列或主题)相关联。这是部署的责任推给消息驱动Bean使用队列或主题相关联。


When using Message Driven BEans, the destination name from where to receive messages is hard coded in the annotation @MessageDriven(mappedName = "someDestinationName")

Is there a way to add this information at runtime? Bellow is a sample Message Driven Bean class.

package mdb.beans;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(mappedName = "someDestinationName", activationConfig =
{
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue =   "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class MDBSample implements MessageListener 
{    
    public MDBSample() 
    {
        // constructor
    }

    @Override
    public void onMessage(Message message) 
    {
        // logic when message received
    }
}

解决方案

As far as I know, no, you cannot do that.

Because, the coupling of the destination (which is a String) and the bean (which is a class) is done once in the deploy-time, you cannot change the destination programmatically.

Maybe there is a hack for re-binding; I mean forcing the container to release MDB, then change destination and re-initalize (go through dependency injection, then post construct steps etc.) but I doubt the application servers will allow that.

Excerpt from JSR-318 (EJB 3.1 spec);

5.4.17 Association of a Message-Driven Beanwith a Destination or Endpoint

A message-driven bean is associated with a destination or endpoint when the bean is deployed in the container. It is the responsibility of the Deployer to associate the message-driven bean with a destination or endpoint.

5.4.17.1 JMS Message-Driven Beans

A JMS message-driven bean is associated with a JMS Destination (Queue or Topic) when the bean is deployed in the container. It is the responsibility of the Deployer to associate the message-driven bean with a Queue or Topic.

这篇关于在邮件配置MappedName注释驱动Bean动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆