1

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

tt0686
  • 1,771
  • 6
  • 31
  • 60
  • 1
    Can you show us a code snippet where you're processing message in MDB? Also which acknowledgment mode is chosen for your provider/consumer communication? – solar Jan 27 '16 at 10:11
  • Is any place where we could configure the acknowledgment in WAS ? – tt0686 Jan 27 '16 at 10:34
  • https://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/SIBJMSActivationSpec_DetailForm.html check here. I'm still not sure that's the cure for your issue, but I've got a similar situation with my MDB in Weblogic, and setting correct acknowledge mode helps me. You could try it anyway – solar Jan 27 '16 at 10:48

1 Answers1

0
@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);
    }

}
Dharmvir Tiwari
  • 886
  • 3
  • 12
  • 25