问题
I've been assigned the task of using Apache Jmeter to connect to an MQ. Unfortunately, I'm not the admin of the MQ, and all my attempts to get more information about it have gotten me nowhere. What I have now is a queue name (call it q), a queue manager (its name, anyway; call it v), a host (w), a port (x), a channel (y), a user (z), and a test message I'm supposed to send across. The object of the game is straightforward: send the test message from Apache Jmeter to the MQ (after which I'll ask the admins whether the message went through or not). In other words, I need help figuring out what to do with Jmeter.
The MQ is version 8.0.0.4. I already have Jmeter installed, so I don't need advice on that (unless there's some special way it should have been installed for this task).
The links provided in this question's answer didn't get me very far. They seemed largely unrelated to what I was trying to do (and also imprecise in their instructions).
回答1:
- Download 8.0.0.4-WS-MQ-Install-Java-All file
- Run it like
java -jar 8.0.0.4-WS-MQ-Install-Java-All.jar
and accept the license agreement - Add all .jars from
wmq/JavaSE/
folder to JMeter Classpath - Restart JMeter to pick the .jars up
Add JSR223 Sampler to your Test Plan and put the following code into "Script" area:
import com.ibm.msg.client.jms.JmsFactoryFactory import com.ibm.msg.client.wmq.WMQConstants import javax.jms.Session // 1 def hostName = "127.0.0.1" def hostPort = 1414 def channelName = "DEV.APP.SVRCONN" def queueManagerName = "QM1" def queueName = "DEV.QUEUE.1" // 2 def ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER) def cf = ff.createConnectionFactory() // 3 cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, hostName) cf.setIntProperty(WMQConstants.WMQ_PORT, hostPort) cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channelName) cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT) cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, queueManagerName) // 4 def conn = cf.createConnection("app", "") def sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE) // 5 def destination = sess.createQueue(queueName) conn.start()
See IBM MQ testing with JMeter - Learn How article for more information if needed.
来源:https://stackoverflow.com/questions/49832345/connecting-to-an-mq-with-jmeter