动态配置消息驱动Bean中的MappedName注解 [英] Configuring MappedName annotation in Message Driven Bean dynamically

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

问题描述

当使用消息驱动 BEans 时,接收消息的目的地名称硬编码在注解中 @MessageDriven(mappedName = "someDestinationName")

有没有办法在运行时添加这些信息?Bellow 是一个示例消息驱动 Bean 类.

package mdb.beans;导入 javax.ejb.ActivationConfigProperty;导入 javax.ejb.MessageDriven;导入 javax.jms.Message;导入 javax.jms.MessageListener;@MessageDriven(mappedName = "someDestinationName", activationConfig ={@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")})公共类 MDBSample 实现 MessageListener{公共 MDBSample(){//构造函数}@覆盖public void onMessage(消息消息){//收到消息时的逻辑}}

解决方案

据我所知,不,你不能那样做.

因为,目标(它是一个字符串)和 bean(它是一个类)的耦合在部署时一次完成,你不能以编程方式更改目标.>

也许有一个重新绑定的技巧;我的意思是强制容器释放 MDB,然后更改目标并重新初始化(通过依赖注入,然后发布构造步骤等),但我怀疑应用服务器会允许这样做.

摘自 JSR-318(EJB 3.1 规范);

<块引用>

5.4.17 消息驱动 Bean 与目的地或端点的关联

在容器中部署消息驱动的 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.

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

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