gpt4 book ai didi

java - 动态配置 Message Driven Bean 中的 MappedName 注解

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:29:38 25 4
gpt4 key购买 nike

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

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

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
}
}

最佳答案

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

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

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

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

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.

关于java - 动态配置 Message Driven Bean 中的 MappedName 注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16033568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com