问题
I have 3 queues and these three queues need to be listened by MDBbean and accordingly based on reading input, i will split out the task for each category of input.
As of now, the code is working fine for only one queue and i don't know how to implement it for more than one queue. Could you please guide me
@MessageDriven(mappedName="receiver1")
public class MDBMessages implements MessageListener
How i can make my MDBMessage to listen for receiver2 and receiver 3 queue.
Thanks Prabhakar
回答1:
From Documentation :
A message-driven bean is defined for a single messaging type, in accordance with the message listener interface it employs.
Therefore it will not be possible to map a MDB for multiple destination types.
Haven't tried, but you can try configuring MDB in ejb-jar.xml with different JNDI names pointing to the same class & add different destination to each of them. If configuration works, then MDBMessages will be able to listen messages for all specified queues in xml.
回答2:
use the deployment descriptor to create multiple instances of your mdb. Each instance listens to one queue.
also there are brokers (like activeMQ) that allow one mdb to listen on multiple destinations of the same type (queue, topic), if they use the activemq resource adapter.
回答3:
@Consumer(activationConfig = { @ActivationConfigProperty(
propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@**ActivationConfigProperty(propertyName = "destination",
propertyValue = "queue/MyTasksProcess"),**
public class MyProcessorMDBean implements Downloader {
public void processSomething(Serializable anyParameter){
//Do the actual processing
}
for a given message driven bean you can rout your message to single queue so can use only single destination type in your bean class.
来源:https://stackoverflow.com/questions/6112760/mulitple-queues-in-ejb-messagedriven-annotation