Configuring MappedName annotation in a managed Bean message dynamically

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

Is there any way to add this information at runtime? Bellow is an example of a 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 } } 
+6
source share
1 answer

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

Since the association of the destination (which is the string) and the bean (which is the class) is done once during deployment, you cannot programmatically change the destination.

Maybe there is a hack for re-binding; I mean forcing the container to issue MDB, then changing the destination and reinitializing (going through dependency injection, then building steps, etc.), but I doubt that application servers will allow it.

Excerpt from JSR-318 (EJB 3.1 Specification);

5.4.17 Association of message-processed Bean with Destination or Endpoint

A message-driven bean is associated with an endpoint or endpoint when the bean is deployed in a container. Deployer's responsibility to associate a message-driven bean with an endpoint or endpoint.

5.4.17.1 JMS Message-Driven Beans

The bean JMS message is associated with a JMS Destination (Queue or Topic) when the bean is deployed in the container. Deployer's responsibility to bind a message-driven bean using a queue or topic.

+2
source

All Articles