In the test environment, the solution to conflicts caused by multiple users using the same environment

  1. Problem Description:

    1. Question one:

Two students, A and B, use the betaA environment to start the service at the same time. At this time, the Dubbo client may not be able to accurately locate a service, and the Kafka message may be consumed by either of the two services. There is a problem that the database status changes, but the log cannot be seen, causing trouble to many students.

  1. Question two:

In order to avoid problem 1, when A test students use betaA, other test and development students cannot use betaA. If you need to use the data in the betaA library urgently, you must modify db.properties, forget to restore after use, and accidentally submit it , causing inconsistencies.

  1. Question three:

Developers can sometimes solve this problem temporarily by modifying dubbo's group and Kafka's group.id, but the problem of wrong submission will also occur.

  1. solution:

A configurable suffix     is ​​added to the group , which is empty by default and has no effect on the existing group

  1. Method to realize

Take betaA as an example

On the basis of the existing group, suffixes can be added arbitrarily through maven's properties, command line, and system parameters.

  1. add suffix variable

    When dubbo is called, it needs to be added to both service.group and reference.group of dubbo, specific to the configuration file, as shown in the figure:

  1. dubbo-provider.properties:

    

  1. dubbo-consumer.properties:

 

  1. kafka.properties:

  1. The default value is set to empty

When this variable is not configured on the command line, the existing state is to be restored without any effect on the existing group. As shown below:

Necessary configuration:

  1. Configure variables on the command line

When compiling and packaging, specify the value of group.suffix on the command line:

  1. Command line add:

mvn clean -DskipTests=true -Dgroup.suffix=zhangxl package

If you use IDE tools, you can also add command line parameters

  1. idea

    Add steps

first step

second step

  1. Eclipse add steps:

Step 1: Run AS à Run Configurations

Part two: as shown

 

  1. Jenkins add steps:

 

  1. Compilation result:


  1. Problems that can be solved:

    1. By adding a dynamic suffix to the group, the conflict between the development and test environments can be resolved without modifying the configuration file.
    2. The default suffix variable value is empty, even if the current group remains unchanged. It only changes when -Dgroup.suffix=value is added to the command line, and the configuration can be freely chosen.
    3. Compatible with command line, IDE tools and Jenkins.
    4. It is recommended that development students configure this variable in the IDE. Test students sometimes need to conduct joint debugging with other systems (such as settlement and capital), which is not suitable for Jenkins for the time being.
  2. Extended extension:

Combining maven's profile and spring's profile can remove all repetitive configurations, such as Kafka's topic and cronExpression configuration of scheduled tasks. For details, see: "Using Maven and Spring's Profile Function to Switch Between Different Operating Environments"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324915888&siteId=291194637