RocketMQ installs and integrates springboot to integrate basic functions in windows environment

RocketMQ installs and integrates the basic functions of springboot in the windows environment

table of Contents

1. RocketMQ download and installation

1.1 Download address: http://rocketmq.apache.org/release_notes/release-notes-4.3.0/​

1.2: Configure the system variables of rocketmq

1.3: Start

2. RocketMQ desktop management plug-in installation and deployment

2.1 Download address: https://github.com/apache/rocketmq-externals.git

2.2 Deploy the plugin

Three. Springboot integrates the basic functions of RocketMQ

3.1 Create a springboot project and add the pom dependency of rocketmq

3.2 configure yml file

3.3 Create Producer Producer 

3.4 Create Consumer 

3.5 Starting the project

3.6: Testing


1. RocketMQ download and installation

RocketMQ is Alibaba's open source messaging middleware: rocketmq is relatively simple to download and install, just download and unzip.

The rocketmq downloaded in this article is version 4.3, the latest version has reached 4.7, you can choose your own version according to your needs

1.1 Download address : http://rocketmq.apache.org/release_notes/release-notes-4.3.0/

 

1.2: Configure the system variables of rocketmq

Variable name: ROCKETMQ_HOME

Variable value: MQ decompression path\MQ folder name (in order to prevent abnormalities, unzip to the English path)

1.3: Start

First enter the bin directory of rocket, cmd enters the command line mode:

1.3.1: Start NAMESERVER: enter the command " start mqnamesrv.cmd ", the following screen will appear after successful startup, do not close the dialog box;

1.3.2: Start BROKER: continue to enter the command " start mqbroker.cmd -n 127.0.0.1:9876 autoCreateTopicEnable=true " in the previous cmd command box , the following dialog box will pop up, do not close the dialog box

 

 

2. RocketMQ desktop management plug-in installation and deployment

2.1 Download address: https://github.com/apache/rocketmq-externals.git

Use github to clone the project in the address;

Deployment premise: java environment, maven environment needs to be available

2.2 Deploy the plugin

2.2.1: Enter the'rocketmq-externals\rocketmq-console\src\main\resources' folder and modify the startup configuration file application.properties;

Start the plug-in port number: server.port=8089 , this can be set randomly, as long as there is no conflict with the port of the existing service in the windows environment

The connection address of rocketmq : rocketmq.config.namesrvAddr=127.0.0.1:9876  

2.2.2: Compile and start the project: enter the'\rocketmq-externals\rocketmq-console' folder, execute ' mvn clean package -Dmaven.test.skip=true' to compile and generate a jar package;

            After successful compilation, Cmd enters the'target' folder, executes'java -jar rocketmq-console-ng-1.0.0.jar', and starts " rocketmq-console-ng-1.0.0.jar "

After successful installation and deployment, visit: localhost:8089, you will see the following interface

Three. Springboot integrates the basic functions of RocketMQ

3.1 Create a springboot project and add the pom dependency of rocketmq

<dependency>
     <groupId>org.apache.rocketmq</groupId>
     <artifactId>rocketmq-spring-boot-starter</artifactId>
     <version>2.1.0</version>
</dependency>

3.2 configure yml file

rocketmq:
  name-server: 127.0.0.1:9876
  producer:
    group: my-producer-group

3.3 Create Producer Producer 

package com.demo.rocketmq.simpleTest;

import io.swagger.annotations.Api;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@RequestMapping("/test")
@RestController
public class Producer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping("send")
    public void send(){
        rocketMQTemplate.convertAndSend("test-topic","你好,Java旅途");
    }

}

3.4 Create Consumer 

package com.demo.rocketmq.simpleTest;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "test-topic",consumerGroup = "my-consumer-group")
public class Consumer implements RocketMQListener<String> {
    @Override
    public void onMessage(String message) {
        log.info("我收到消息了!消息内容为:"+message);
    }
}

3.5 Starting the project

3.5.1: You need to configure topic before startup: you can add it on the management console page

3.5.2: Visit address: http:/127.0.0.1/test/send, you can see the log generated by the project console.

3.6: Testing

Use jemeter to test the effect: Of course, you can also use postman to test: I am used to test what will happen with high concurrency;

Configure the number of threads:

 

Configure url:

Check the performance consumption of the computer: As can be seen from the figure below, the CPU utilization has reached 100%, and the memory has reached 12G, and it lasts for a long time. It has been processing the request, and it will be processed after a while .

The above is the simple integration steps of rocketmq installation and deployment. This is only the simplest integration step. The actual use is far more than this. Interested students can learn about the method of RocketMQ packaging.

Follow-up bloggers will also supplement the use of related RocketMQ packages, and everyone will learn and make progress together.

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_37488998/article/details/111240175