0
votes

I am using IBM MQ to produce messages while receiving it through a consumer on my client. To create the connection I'm using JmsConnectionFactory, along with provided properties to set up the connection with the server. So from what I understand is, as the consumer the only way to recognize the messages produced by the server is through the onMessage call. I'm currently testing this by creating a local producer and local consumer and assuring that every message sent by the producer is received by the consumer.

I'm running into the following problems:

  1. I'm not receiving all messages produced.
  2. Depending on the size of the message, more of them are received if they are smaller.

Here is code for the creation of the producer:

JmsConnectionFactory cf = ff.createConnectionFactory();

cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, qm.getHost());

int port = ###;
cf.setIntProperty(WMQConstants.WMQ_PORT, port);
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, qm.getChannel());
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, qm.getQueueManagerName());

Connection connection = cf.createConnection(qm.getUser().getUsername(), qm.getUser().getPassword());
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

Destination destination = session.createQueue(qm.getDestinationName());
LOG.debug("Destination Created at " +qm.getDestinationName());

msgSender = session.createProducer(destination);
msgSender.setDeliveryMode(DeliveryMode.PERSISTENT);   

And this is how the producer is sending messages:

/**
 * msgSender is the MessageProducer object
 **/
private void produceMessages(int numOfMessages) throws JMSException, InterruptedException {
    for (int i = 0; i < numOfMessages; i++) {
        String text = "Message #" +i;
        TextMessage message = session.createTextMessage(text);
        msgSender.send(message);
    }
}

On the consumer side, I am simply printing received messages and verifying visually:

@Override
public void onMessage(Message m) {
    System.out.println(((TextMessage)m).getText());
}

I am not fully familiar with how IBM MQ works. Could the reason for the missing messages reside on the MQ simply ignoring messages that are produced before a message is fully sent?

2

2 Answers

0
votes

I would say the issue is residing on your consumer side, rather than your simulated producer. Your message producer should be sending messages to MQ just fine, but multiple consumers are probably competing to retrieve these messages from the connection you have set up (given the same queue manager properties). So unless no one else is trying to consume from your IBM MQ, you're going to be expected to miss some messages.

0
votes

You should use other method of send(Message m, CompletionListener l) to send new messages only after completion. And if you use "Best Effort", it still will lose messages. You can try "Express" instead.