美文网首页
ActiveMQ环境搭建及性能测试

ActiveMQ环境搭建及性能测试

作者: Gallrax | 来源:发表于2018-03-04 18:40 被阅读0次

虚拟机环境

cpu:E5-1650 v2 分配2个物理核心 每个核心2两个线程
内存:4G

环境搭建

>wget http://www.apache.org/dyn/closer.cgi?filename=/activemq/5.15.3/apache-activemq-5.15.3-bin.tar.gz&action=download
>tar -zxvf apache-activemq-5.15.3-bin.tar.gz
>./activemq start

性能测试

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

application.yml

spring:
  activemq:
    broker-url: tcp://192.168.66.6:61616
    user: admin
    password: admin
# 若想activemq启用topic,需开启此项
  jms:
    pub-sub-domain: true

provider

package com.activemq.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import javax.jms.Topic;

@Component
public class ActiveMQClient {

    @Autowired
    private JmsTemplate jmsTemplate;
    @Autowired
    private Queue queue;
    @Autowired
    private Topic topic;

    public void send(String message) {
        //默认不注入Queue和Topic时,使用Queue
//        jmsTemplate.convertAndSend("testMQ", message);
        //1.测试queue性能
//        jmsTemplate.convertAndSend(queue, message);
        //2.测试topic性能
        jmsTemplate.convertAndSend(topic, message);
    }

}

consumer

package com.activemq.server;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.Queue;

@Component
public class ActiveMQServer {

//    @JmsListener(destination = "testMQ")
//    @JmsListener(destination = "testMQ-queue")
    @JmsListener(destination = "testMQ-topic")
    public void receive(String message) {
        System.out.println(" now : "+ System.currentTimeMillis());
        System.out.println(" activeMQ receive : " + message);
    }
}

测试类

package com.test;

import com.Application;
import com.activemq.client.ActiveMQClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StopWatch;

import java.io.IOException;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class ActiveMQTest {

    @Autowired
    private ActiveMQClient activeMQClient;

    /*
        queue
        ActiveMQ 生产消费同时启动   生产10000条数据:89000ms
        ActiveMQ 只生产不消费启动   生产10000条数据:84000ms
        ActiveMQ 只消费不生产启动   消费10000条数据:14471ms
        topic
        ActiveMQ 生产消费同时启动   生产10000条数据:80605ms
        ActiveMQ 只生产不消费启动   生产10000条数据:78867ms
        ActiveMQ 只消费不生产启动   消费10000条数据:无法设置
     */
    @Test
    public void test01() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int i = 0; i < 10000; i++) {
            activeMQClient.send("send : " + i);
        }
        stopWatch.stop();
        System.out.println(" send 10000 共耗时 : " + stopWatch.getTotalTimeMillis());
    }

    @Test
    public void test02() throws IOException {
        //项目启动之后,Queue消费者则自动消费队列数据,根据消费者提供时间进行计算
        System.in.read();
    }

}

项目地址

gitee:https://gitee.com/gallrax/TestMQ
github:https://github.com/gallrax/TestMQ

相关文章

  • ActiveMQ环境搭建及性能测试

    虚拟机环境 cpu:E5-1650 v2 分配2个物理核心 每个核心2两个线程内存:4G 环境搭建 性能测试 po...

  • LR 第一节

    性能测试流程 注意点: 性能测试用例设计,特别关注数据容量的问题性能测试环境搭建,与被测试环境区分开执行:跑脚本、...

  • 软件测试环境搭建

    搭建测试环境前后要注意以下几点: 1.搭建测试环境前,确定测试目的 即是功能测试,稳定性测试,还是性能测试,测试目...

  • ActiveMq深入简出(二)---- ActiveMq与Spr

    ActiveMq与SpringBoot集成 基于SpringBoot快速搭建ActiveMq开发环境,实现消息队列...

  • 【第二章】jmeter环境搭建与实战

    本章大纲 jmete性能测试工具简介 jmete运行环境搭建 jmete基本使用 jmete性能测试工具简介 多线...

  • Vue单元测试case写法

    书接上文,karma+webpack搭建vue单元测试环境介绍了vue单元测试环境搭建及查看源文件的测试覆盖覆盖率...

  • 性能测试学习笔记2——流程

    1.流程性能需求分析确认——制定测试计划——编写测试用例——搭建测试环境——构造测试数据——脚本开发——执行测试—...

  • 随笔:测试移动应用的挑战

    做好性能测试,从来就不是一件简单容易的事。搭建与生产环境相同的性能测试环境一直是做性能测试的第一步,也是很重要的一...

  • Jmeter性能测试环境搭建

    一、环境配置 linux环境 (本次使用的jmeter4.0需要jdk1.8及以上版本才支持)  1. 创建目录,...

  • ActiveMQ 环境搭建与测试(C++)

    一、下载安装jdk jdk官网下载地址:https://www.oracle.com/technetwork/ja...

网友评论

      本文标题:ActiveMQ环境搭建及性能测试

      本文链接:https://www.haomeiwen.com/subject/lykqfftx.html