使用Gatling的JMS-Loadtest:无法初始化IBM MQ的

时间:2018-02-14 08:46:53

标签: ibm-mq gatling scala-gatling

我正在针对带有Gatling的IBM MQ实施负载测试场景。 设置与提到的here

基本相同

问题:我无法使用IBM MQ初始化所需的ContextFactory - 应该是com.ibm.mq.jms.context.WMQInitialContextFactory。 无法找到WMQInitialContextFactory

但我的build.sbt正确包含IBM MQ依赖项(由我们的内部Nexus成功检索:

"com.ibm.mq" % "com.ibm.mq" % "8.0.0.3"  

我的情节:

package com.myawesomecompany.loadtest

import com.ibm.mq._
import com.ibm.mq.jms.MQConnectionFactory
import com.ibm.mq.jms.JMSMQ_Messages
import com.ibm.msg.client.wmq.common.CommonConstants
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.jms.Predef._
import javax.jms._

import scala.concurrent.duration._

class JMSLoadTest extends Simulation {

  val jmsConfiguration = jms
    .connectionFactoryName("ConnectionFactory")
    .url("devmq01.company.dmz")
    .credentials("mqm", "mqm")

  .contextFactory(classOf[com.ibm.mq.jms.context.WMQInitialContrextFactory].getName) 
  .listenerCount(1)
  .usePersistentDeliveryMode  

 val scn = scenario("Load testing GPRSForwarder").repeat(1) {
exec(jms("testing GPRSForwarder...").reqreply
  .queue("COMPANY.TEST.QUEUE")
  .textMessage("00001404020611100E033102C20EBB51CC1C036EFFFF00010002323802000200FE05001400000000FFFFFFFFFFFFFFFFFF040010038B0D6912EB10CE070206110F37298C")
  .jmsType("test_jms_type")
    )
  }  

 setUp(scn.inject(rampUsersPerSec(10) to 1000 during (2 minutes)))
    .protocols(jmsConfiguration)


}  

设置相当于this one - 但我没有使用ActiveMQInitalContextFactory,而是强行使用"对应" IBM MQ。

根据official docksWMQInitialContextFactory应该在com.ibm.mq.jms.context,但事实并非如此。矿石在CommonConstants中有一些常数,我可以用来初始化ContextFactory吗?

提前多多感谢。

2 个答案:

答案 0 :(得分:1)

  

问题:我无法初始化所需的ContextFactory   IBM MQ - 应该是   com.ibm.mq.jms.context.WMQInitialContextFactory。该   找不到WMQInitialContextFactory。

不要使用WMQInitialContextFactory。这是一个MQ SupportPac创建者,他们希望将MQ用作JNDI存储库。这不是一个好主意,而且SupportPac不支持任何形式的安全性(即SSL / TLS或安全性退出)。

您应该使用基于文件的MQ JNDI。这是一个基本的例子:

import java.util.Hashtable;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.ibm.mq.MQException;

/**
 * Program Name
 *  TestJMS01
 *
 * Description
 *  This java JMS class will connect to a remote queue manager
 *  using JNDI and put a message to a queue.
 *
 * Sample Command Line Parameters
 *  -x myQCF -q dev.test.q -f C:\JNDI-Directory\roger\mqjndi
 *
 *  Sample MQ JNDI Commands:
 *    DEFINE QCF(myQCF) QMANAGER(MQA1) CHANNEL(TEST.CHL) HOSTNAME(127.0.0.1) PORT(1415) TRANSPORT(CLIENT) FAILIFQUIESCE(YES)
 *    DEFINE Q(dev.test.q) QUEUE(TEST1) QMANAGER(MQA1) TARGCLIENT(JMS) FAILIFQUIESCE(YES)
 *
 * @author Roger Lacroix, Capitalware Inc.
 */
public class TestJMS01
{
   private static final String JNDI_CONTEXT = "com.sun.jndi.fscontext.RefFSContextFactory";

   private QueueConnectionFactory cf;
   private Queue q;
   private Hashtable<String,String> params = null;
   private String userID = "tester";
   private String password = "mypwd";

   public TestJMS01() throws NamingException
   {
      super();
   }

   /**
    * Make sure the required parameters are present.
    * @return true/false
    */
   private boolean allParamsPresent()
   {
      return (params.containsKey("-x") && params.containsKey("-q") && params.containsKey("-f"));
   }

   /**
    * Extract the command-line parameters and initialize the MQ variables.
    * @param args
    * @throws IllegalArgumentException
    */
   private void init(String[] args) throws IllegalArgumentException
   {
      params = new Hashtable<String,String>(10);
      if (args.length > 0 && (args.length % 2) == 0)
      {
         for (int i = 0; i < args.length; i += 2)
         {
            params.put(args[i], args[i + 1]);
         }
      }
      else
      {
         throw new IllegalArgumentException();
      }

      if (allParamsPresent())
      {
         Hashtable<String,Object> env = new Hashtable<String,Object>();
         env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_CONTEXT);
         env.put(Context.PROVIDER_URL, "file:/"+(String) params.get("-f"));

         try
         {
            Context ctx = new InitialContext(env);

            cf = (QueueConnectionFactory) ctx.lookup((String) params.get("-x"));
            q = (Queue) ctx.lookup((String) params.get("-q"));
         }
         catch (NamingException e)
         {
            System.err.println(e.getLocalizedMessage());
            e.printStackTrace();
            throw new IllegalArgumentException();
         }
      }
      else
      {
         throw new IllegalArgumentException();
      }
   }

   /**
    * Test the connection to the queue manager.
    * @throws MQException
    */
   private void testConn() throws JMSException
   {
      QueueConnection connection = null;
      QueueSession session = null;

      try
      {
         connection = cf.createQueueConnection(userID, password);
         connection.start();

         session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

         sendMsg(session);
      }
      catch (JMSException e)
      {
         System.err.println("getLinkedException()=" + e.getLinkedException());
         System.err.println(e.getLocalizedMessage());
         e.printStackTrace();
      }
      finally
      {
         try
         {
            session.close();
         }
         catch (Exception ex)
         {
            System.err.println("session.close() : " + ex.getLocalizedMessage());
         }

         try
         {
            connection.stop();
         }
         catch (Exception ex)
         {
            System.err.println("connection.stop() : " + ex.getLocalizedMessage());
         }

         try
         {
            connection.close();
         }
         catch (Exception ex)
         {
            System.err.println("connection.close() : " + ex.getLocalizedMessage());
         }
      }
   }

   /**
    * Send a message to a queue.
    * @throws MQException
    */
   private void sendMsg(QueueSession session) throws JMSException
   {
      QueueSender sender = null;

      try
      {
         TextMessage msg = session.createTextMessage();
         msg.setText("Nice simple test. Time in 'ms' is  -> " + System.currentTimeMillis());
         // msg.setJMSReplyTo(tq);
         // msg.setJMSDeliveryMode( DeliveryMode.NON_PERSISTENT);

         System.out.println("Sending request to " + q.getQueueName());
         System.out.println();

         sender = session.createSender(q);
         sender.send(msg);
      }
      catch (JMSException e)
      {
         System.err.println("getLinkedException()=" + e.getLinkedException());
         System.err.println(e.getLocalizedMessage());
         e.printStackTrace();
      }
      finally
      {
         try
         {
            sender.close();
         }
         catch (Exception ex)
         {
            System.err.println("sender.close() : " + ex.getLocalizedMessage());
         }
      }
   }

   /**
    * main line
    * @param args
    */
   public static void main(String[] args)
   {
      try
      {
         TestJMS01 tj = new TestJMS01();
         tj.init(args);
         tj.testConn();
      }
      catch (IllegalArgumentException e)
      {
         System.err.println("Usage: java TestJMS01 -x QueueConnectionFactoryName -q JMS_Queue_Name -f path_to_MQ_JNDI");
         System.exit(1);
      }
      catch (NamingException ex)
      {
         System.err.println(ex.getLocalizedMessage());
         ex.printStackTrace();
      }
      catch (JMSException e)
      {
         System.err.println("getLinkedException()=" + e.getLinkedException());
         System.err.println(e.getLocalizedMessage());
         e.printStackTrace();
      }
      catch (Exception ex)
      {
         System.err.println(ex.getLocalizedMessage());
         ex.printStackTrace();
      }
   }
}

答案 1 :(得分:-1)

与您的问题没有直接关系,但JMSToolBox及其脚本功能是一个允许在IBM MQ上执行批量/负载测试的工具。

有了它,您可以定义一个由script组成的steps,它会在template个占位符中读取variable并重复将消息放入一个或多个目的地。它还可以直接从目录等中读取已保存的消息。

您可以从SourceForge here下载 脚本功能is here

的文档