1
votes

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

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
Is any place where we could configure the acknowledgment in WAS ?tt0686
www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/… 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 anywaysolar

1 Answers

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

}