Reputation: 1849
Good morning in my timezone.
Application Server -> WAS 7 EJB 3.0
In the project i am working on, we are using an Message-Driven bean to read messages from a queue. This Message-Driven bean read two times the same message and in the second read it throws an exception because an integrity constraint in a database insert. Why is this Message-driven bean reading the message two times. We are using just one listener on the queue and there is just one MDB attached to that listener. We are using the following ActivationConfigProperty through annotations 1 messageSelector 2 destinationType 3 destination
Code Snippet
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "ResponseType = 'XXXXX'"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/YYYY")})
Thanks in advance Best regards
Upvotes: 1
Views: 884
Reputation: 916
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "java:/jms/queue/data"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
Use this configuration for specifying the acknowledgement for the message,i also think we need to specify the destinationLookup or destination property for specifying strict point to point communication.
Use a message listener to verify when exactly the message is being received and time to live for the message being published
@Stateless
public class MessageSender {
@Inject
JMSContext jmsContext;
public void sendMessage(String message, Destination destination) {
JMSProducer messageProducer = jmsContext.createProducer().setAsync(
new CompletionListener() {
public void onException(Message message, Exception exception) {
System.out
.println("Message not delivered!!!!\nAn exception has occured "
+ exception);
}
public void onCompletion(Message message) {
System.out
.println("Message delivered : hooah ");
}
});
// To check if both the messages are getting expired after the mentioned time
messageProducer.setTimeToLive(6000);
messageProducer.send(destination, message);
}
}
Upvotes: 0