How to add a Selector with MDB 3.0 ?

Message selectors allow an MDB to be more selective about the messages it receives from a particular topic or queue. Message selectors use Message properties as criteria in conditional expressions. (Message selectors are also based on message headers, which are outside the scope of this chapter.) These conditional expressions use Boolean logic to declare which messages should be delivered to a client. 

Now with MDB 3.0 it's easier to configure a selector : simply add an @ActivationConfigProperty at the top of your MDB:

@MessageDriven(activationConfig = {
  
  @ActivationConfigProperty(propertyName = "messageSelector",propertyValue = "color= 'red'")}
)


public class Mdbsample implements MessageListener {
 ... 
}   

On the other end, you can set a Selector on your Producer by setting a String property as follows:

Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(true, 0);
Message message = session.createMessage();
message.setStringProperty("color", "yellow");
JMSProducer producer = context.createProducer();

producer.send(queue, message);

Related articles available on mastertheboss.com

EJB 3.0 tutorial : Session Beans

Enterprise JavaBeans (EJB) technology is a J2EE technology for de

JBoss MDB 3.0

Message-driven beans (MDBs) are stateless, server-side, transacti

JBoss EJB 3 BMT

In a Bean Managed Transaction, the code in the session or message

How do you keep your EJB callbacks separated from biz. methods?

JBoss daily recipe

How to set EJB timeout period ?

JBoss recipe of the day

How to create a MDB 3.0 singleton ?

  EJB3 uses the resource adapter.  When using the resource adapt

Follow us on Twitter