0

I'm trying to send a lot of JMS messages to an IBM MQ broker with the awesome Apache Camel library.

When I'm sending 1000 small (less than 100 bytes) messages sending rate is really slow (1 msg/second) with Apache Camel. When I'm doing the same send without Camel sending rate is 50 msg/second. I don't understand why because the two examples are using an MQConnectionFactory with the same parameters.

Here is the code with Apache Camel library:

MQConnectionFactory factory = new MQConnectionFactory();

factory.setHostName("tcp://myhost");
factory.setPort(1414);
factory.setChannel("mychannel");
factory.setQueueManager("myqueuemanager");
factory.setAppName("myAppName");
factory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
factory.setStringProperty(WMQConstants.USERID, "myuser");
factory.setStringProperty(WMQConstants.PASSWORD, "mypassword");

// Set SSL properties for MTLS
factory.setSSLCipherSuite(this.localConf.getString("ssl.ciphers"));
System.setProperty("javax.net.ssl.keyStore",  "somekeystore.js");
System.setProperty("javax.net.ssl.keyStorePassword",  "mykeystorepassword");
System.setProperty("javax.net.ssl.trustStore", "somekeystore.js");
System.setProperty("javax.net.ssl.trustStorePassword",  "mykeystorepassword.js");

var component = JmsComponent.jmsComponentClientAcknowledge(factory);


//Creating a new camel context
context = new DefaultCamelContext();
context.addComponent( "ibmmq", component);

context.addRoutes(new RouteBuilder() {
    @Override
    public void configure() {
        from("timer:myTimer?period=1&delay=0").setBody(constant("message content inferior to 100 bytes"))
        //Envois vers IBM
        .to("ibmmq:queue:myQueueName");
    }
});

context.start();

I'm lost in the resolution of this issue:

  • it can't be a broker limitation because my standard test without Camel is 50x faster
  • it can't be the factory because it's the same in two tests

Is there a misconfiguration in my Camel code?

Edit

Here is my simple java code without camel running 50x faster:

// Variables
        JMSContext context = null;
        Destination destination = null;
        JMSProducer producer = null;
        JMSConsumer consumer = null;

        try {
            // Create a connection factory
            JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
            JmsConnectionFactory cf = ff.createConnectionFactory();

            // Set the properties
            cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, host);
            cf.setIntProperty(WMQConstants.WMQ_PORT, port);
            cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channel);
            cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
            cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, qManagerName);
            cf.setStringProperty(WMQConstants.WMQ_APPLICATIONNAME, "JmsPutGet (JMS)");
            cf.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, true);
            cf.setStringProperty(WMQConstants.USERID, user);
            cf.setStringProperty(WMQConstants.PASSWORD, password);


             context = cf.createContext();
             destination = context.createQueue("queue:///" + qname);

             for(int i=0;i<1000;i++){
                 long uniqueNumber = System.currentTimeMillis() % 1000;
                 TextMessage message = context.createTextMessage("Your lucky number today is " + uniqueNumber);
                 message.setStringProperty("myCustomHeader","header1");

                 producer = context.createProducer();
                 producer.send(destination, message);
                 System.out.println("Sent message:\n" + message);

             }

             context.close();

nb: if i create a custom component on camel with my simple java code in it, the speed is 50msg/sc too so i think the problem coming from the JmsComponent.jmsComponentClientAcknowledge() but i dont know why and i dont want to rewrite the all component and it's safety mechanisms (it's so risky)

8
  • What exactly is your non-Camel code doing? Is it just looping over the send method on the JMS MessageProducer? If so, that code is doing considerably less work than Camel although I'm not sure that would account for the entire 50x difference. Have you tried profiling the Camel code to see where it's spending its time? Commented Feb 10 at 15:33
  • We would need to see your non-Camel code, but this Camel code is sending persistent messages to MQ, so if your other code doesn’t that could explain a significant part of the throughput difference. I wouldn’t expect a 50x difference but maybe your storage under MQ is really slow, that would make persistent messages more expensive. Commented Feb 11 at 9:04
  • I've edited my post to add the simple java example. I'm agree camel does extra things, but that can't justify a slowdown 50 times slower in my opinion. Commented Feb 11 at 13:30
  • If you add producer.setDeliveryMode(DeliveryMode.PERSISTENT); to your simple Java example, you can check if it is related to persistent messages vs. non-persistent messages. Commented Feb 11 at 17:00
  • Do you use a timer with the same name ("myTimer") more than once? Doc says, if you use the same name for all your timer endpoints, only one Timer object and thread will be used. I am note sure what this means for the timer options you set here. If the timer is set with the default period=1000 somewhere else, it may explain your message rate of 1msg/s. Commented Feb 11 at 17:25

2 Answers 2

0

Camel's timer 'period' is in milliseconds, so that Camel route will never run faster than 1,000 msg/s.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, my problem is that this code send only 1 msg/s ....
0

Keeping in mind as well, that the Camel code will establish a JMS connection to MQ, send the message, then drop the JMS connection for every iteration.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.