LESSON5: Using JMeter to measure Message Queuing (ACTIVEMQ)

Source: Internet
Author: User

This article describes the use of JMeter to test the message queue, where Message Queuing using Apache Activemq,jmeter itself is supported by the JMS standard Message Queuing test, due to the jmeter of the official sampler configuration is more complex, This article uses the method of the SDK directly to the pressure measurement, and the actual use of the production closer, you are interested in the official sampler, you can configure the completion of their own.

Ready to work: Download ACTIVEMQ address: http://activemq.apache.org The ACTIVEMQ in this article is in version 5.9.0.

Jmetterlessons Project Source Address: Https://github.com/mantuliu/jMetterLessons

1. Unzip the downloaded ACTIVEMQ package, do not have the Chinese name in the directory, and then execute the activemq.bat command in the bin directory, the command line output is similar to the following interface, proving that the ACTIVEMQ started successfully:

2. Visit the site: Http://localhost:8161/admin user name: admin Password: admin login successful, ACTIVEMQ management interface as shown below, there is no corresponding queue:

3. Add the following dependencies to the Pom file under Engineering jmeterlessions:

    <Dependency>      <groupId>Org.apache.geronimo.specs</groupId>      <Artifactid>Geronimo-jms_1.1_spec</Artifactid>      <version>1.1</version>    </Dependency>    <Dependency>      <groupId>Org.apache.activemq</groupId>      <Artifactid>Activemq-client</Artifactid>      <version>5.9.0</version>    </Dependency>    <Dependency>      <groupId>Org.slf4j</groupId>      <Artifactid>Slf4j-nop</Artifactid>      <version>1.7.5</version>    </Dependency>

4. Regenerate the Eclipse project using MVN eclipse:eclipse, and the command automatically downloads the relevant package during execution

5. The sender class for calling ACTIVEMQ is as follows:

 PackageCom.mantu.jmeter;Importorg.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;ImportOrg.apache.jmeter.protocol.java.sampler.JavaSamplerContext;ImportOrg.apache.jmeter.samplers.SampleResult;Importorg.apache.activemq.ActiveMQConnectionFactory;ImportOrg.apache.activemq.command.ActiveMQQueue;Importjavax.jms.*;/*** Bloghttp://www.cnblogs.com/mantu/ * * @authorMantu **/ Public classLesson5extendsabstractjavasamplerclient{ Public Static voidmain (String [] args) {} @Override Publicsampleresult runtest (Javasamplercontext arg0) {//TODO auto-generated Method StubSampleresult sr =NewSampleresult (); Sr.setsamplelabel ("Activemq Test"); Try{Sr.samplestart (); String User= env ("Activemq_user", "admin"); String Password= env ("Activemq_password", "PASSWORD"); String Host= env ("Activemq_host", "localhost"); intPort = Integer.parseint (env ("Activemq_port", "61616"))); String Destination= "Event"; intMessages = 10; intSize = 256; String DATA= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String Body= "";  for(inti=0; i < size; i + +) {Body+ = Data.charat (i%data.length ()); } activemqconnectionfactory Factory=NewActivemqconnectionfactory ("tcp://" + Host + ":" +port); Connection Connection=factory.createconnection (user, password);            Connection.start (); Session Session= Connection.createsession (false, Session.auto_acknowledge); Destination dest=Newactivemqqueue (destination); MessageProducer producer=Session.createproducer (dest);                Producer.setdeliverymode (deliverymode.non_persistent);  for(intI=1; I <= messages; i + +) {textmessage msg=Session.createtextmessage (body); Msg.setintproperty ("id", i);                Producer.send (msg); if((i% 1000) = = 0) {System.out.println (String.Format ("Sent%d Messages", i)); }} producer.send (Session.createtextmessage ("SHUTDOWN"));            Connection.close (); Sr.setresponsedata ("Success");            Sr.setdatatype (Sampleresult.text); Sr.setsuccessful (true); }        Catch(Exception ex) {sr.setsuccessful (false);        Ex.printstacktrace (); }        finally{sr.sampleend (); }        returnSR; }        Private Staticstring env (string key, String defaultvalue) {string RC=system.getenv (key); if(rc==NULL )            returnDefaultValue; returnRC; }    Private StaticString arg (string []args,intindex, String DefaultValue) {        if(Index <args.length)returnArgs[index]; Else            returnDefaultValue; }}

6. Export Jmetterlessons project as jar file, output to JMeter lib/ext directory and copy Activemq-all-5.9.0.jar (this file can be found in activemq) to JMeter Lib/ext directory
7. Configure the Java request and configure the class as Lesson5

After starting the stress test, you can find that the queue has been created in the site Http://localhost:8161/admin, and the corresponding message is generated in the queue, this article shows the pressure test method of the producer of the Activemq queue, and the principle is similar to the consumer. You can simulate it yourself.

LESSON5: Using JMeter to measure Message Queuing (ACTIVEMQ)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.