download:Focus on Java performance optimization to build a hundred million traffic seckill system (bonus seckill project)

In the course, by virtue of the case of “e-commerce seckilling” and various performance optimization techniques, the classic performance optimization techniques of “Seckilling” in the Internet project are summarized, which provides unified design thinking and thinking mode to help students truly understand the use of each technology in performance optimization and the principle behind it. Suitable for Java junior and intermediate engineers, Technical reserve: Familiar with SSM and SpringBoot framework basic applications; familiar with Linux basic commands; familiar with Redis common commands; unzip downloaded zip files

Windows directly austerity software decompression can be

linux

Unzip rocketmq-all-4.8.0-source-release.zip CD Rocketmq-all-4.8.0 / mvn-prelease – all-dskiptests clean install -u CD rocketmq-all-4.8.0/ mvn-prelease – all-dskiptests clean install -u CD Distribution/target/rocketmq – 4.8.0 / rocketmq – 4.8.0 set the environment variable Set Windows demand here, Linux doesn’t demand, of course, I don’t have a test in the Linux environment, have fun little fellow himself to experiment. Add the following environment variables in Windows:

ROCKETMQ_HOME = “D: \ workspace \ tools \ rocketmq – all – 4.8.0 – bin – release” NAMESRV_ADDR = “localhost: 9876”! [] ()

! [image-20210310230651594]()

Or set it in the Powershell window before startup. This is temporary.

Env: ROCKETMQ_HOME = “D: workspacetoolsrocketmq – all – 4.8.0 – bin – release” Env: ROCKETMQ \ _HOME = “D: \ \ workspace \ \ tools \ \ ROCKETMQ – all – 4.8.0 – bin – release “Env: ROCKETMQ_HOME =” D: workspacetoolsrocketmq – all – 4.8.0 – bin – release “Env: NAMESRV_ADDR =” localhost: 9876″ Start Start Name Service Linux

nohup sh bin/mqnamesrv &

tail -f ~/logs/rocketmqlogs/namesrv.log

The Name Server boot success…

windows

Start powerShell. If environment variables are not set, perform the following operations to stop setting environment variables

Env: ROCKETMQ_HOME = “D: workspacetoolsrocketmq – all – 4.8.0 – bin – release” Env: ROCKETMQ \ _HOME = “D: \ \ workspace \ \ tools \ \ ROCKETMQ – all – 4.8.0 – bin – release “Env: ROCKETMQ_HOME =” D: workspacetoolsrocketmq – all – 4.8.0 – bin – release “Env: NAMESRV_ADDR =” localhost: 9876″ Then go to the rocketMQ appliance directory and do the following

CD D: \ workspace \ tools \ rocketmq – all – 4.8.0 – bin – release. \ bin \ mqnamesrv CMD! [] ()

! [] ()

Start agent Service Linux

nohup sh bin/mqbroker -n localhost:9876 & tail -f ~/logs/rocketmqlogs/broker.log The broker[%s, 172.30.30.233:10911] the boot success… windows

Just like starting the Name service above, the previous two lines of setting the environment variable are performed before setting the environment variable

Env: ROCKETMQ_HOME = “D: workspacetoolsrocketmq – all – 4.8.0 – bin – release” Env: ROCKETMQ \ _HOME = “D: \ \ workspace \ \ tools \ \ ROCKETMQ – all – 4.8.0 – bin – release “Env: ROCKETMQ_HOME =” D: workspacetoolsrocketmq – all – 4.8.0 – bin – release “Env: NAMESRV_ADDR =” localhost: 9876″ Then perform the startup operation

CD D:\workspace\tools\ rocketmq-all-4.8.0-bin-release.\ bin\mqbroker.cmd -n localhost:9876 autoCreateTopicEnable=true Before operation, be sure to enter the rocketMQ device directory, otherwise reward the following red error

! [] ()

Accept & Send Voice Messages Send voice messages Linux

export NAMESRV_ADDR=localhost:9876

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

SendResult [sendStatus=SEND_OK, msgId= …

windows

Similarly, if you do not set environment variables, remember to set them first. If you do not bother to set eternal environment variables, refer to Setting environment variables

CD D: \ workspace \ tools \ rocketmq – all – 4.8.0 – bin – release. \ bin \ tools. CMD org. Apache. Rocketmq. Example. The quickstart. Producer After executing the command, you will see that we have sent many messages to the message queue

! [] ()

Accept voice Linux

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

ConsumeMessageThread_%d Receive New Messages: [MessageExt…

windows

Also, if you haven’t set environment variables, set them first

CD D: \ workspace \ tools \ rocketmq – all – 4.8.0 – bin – release. \ bin \ tools. CMD org. Apache. Rocketmq. Example. The quickstart. Consumer After executing the command above, you can see the message received by the console

! [] ()

Java simple demo here in the official website can be seen, are also very simple, requirements supplement clarify, I will stop to explain. Before starting the project, introduce the following dependencies:

Org. Apache. Rocketmq rocketmq - client 4.3.0Copy the code

Send a synchronous audio import org. Apache. Rocketmq. Client. Producer. DefaultMQProducer; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; / * *

  • @program: rocketmq-demo

  • @description: Sends synchronous messages

  • @author: syske

  • @create: 2021-03-09 20:24

    / public class SyncProducer {public static void main(String[] args) throws Exception {// Instantiate the Producer DefaultMQProducer producer = new DefaultMQProducer(“please_rename_unique_group_name”); // Set the address of NameServer (producer.setNamesrvaddr (“localhost:9876”)); // Start Producer instance producer.start(); for (int i = 0; i < 100; Message MSG = new Message(“TopicTest”) {// Set Topic, Tag and Message body MSG = new Message(“TopicTest” /

    Topic

    /,

    “TagA” /

    Tag

    /,

    (“Hello RocketMQ ” + i).getBytes(RemotingHelper.DEFAULT_CHARSET) /

    Message body */ ); // Send a message to a Broker SendResult SendResult = producer. Send (MSG); Printf (“%s%n”, sendResult); } // If no more messages are sent, close the Producer instance. producer.shutdown(); }} to send an asynchronous audio import org. Apache. Rocketmq. Client. Producer. DefaultMQProducer; import org.apache.rocketmq.client.producer.SendCallback; import org.apache.rocketmq.client.producer.SendResult; import org.apache.rocketmq.common.CountDownLatch2; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; import java.util.concurrent.TimeUnit; / * *

  • @program: rocketmq-demo

  • @description: Asynchronous message consumer

  • @author: syske

  • @create: 2021-03-09 20:28 */ public class AsyncProducer { public static void main(String[] args) throws Exception { // Producer DefaultMQProducer = new DefaultMQProducer(“please_rename_unique_group_name”); // Set the address of NameServer (producer.setNamesrvaddr (“localhost:9876”)); // Start Producer instance producer.start(); producer.setRetryTimesWhenSendAsyncFailed(0); int messageCount = 100; Final CountDownLatch2 countDownLatch = new CountDownLatch2(messageCount); for (int i = 0; i < messageCount; i++) { final int index = i; // Create a Topic. MSG = new Message(“TopicTest”, “TagA”, “OrderID188”, “Hello world”.getBytes(RemotingHelper.DEFAULT_CHARSET)); // SendCallback accepts the callback of the asynchronously returned result. new SendCallback() {br/>@Override public void onSuccess(SendResult sendResult) { System.out.printf(“%-10d OK %s %n”, index,br/>sendResult.getMsgId()); } @Override public void onException(Throwable e) { System.out.printf(“%-10d Exception %s %n”, index, e); e.printStackTrace(); }}); } // wait 5s countdownlatch.await (5, timeunit.seconds); // If no more messages are sent, close the Producer instance. producer.shutdown(); }} Send unidirectional messages Unidirectional messages are messages with no return value; %3Cbr/%3E%7D%3Cbr/%3E@Override%3Cbr/)

; %3Cbr/%3E%7D%3Cbr/%3E@Override%3Cbr/)

[

import org.apache.rocketmq.client.producer.DefaultMQProducer; import org.apache.rocketmq.common.message.Message; import org.apache.rocketmq.remoting.common.RemotingHelper; / * *

](mailto:br/%3EsendResult.getMsgId()); %3Cbr/%3E%7D%3Cbr/%3E@Override%3Cbr/)

[* @program: rocketmq-demo

  • @description: One-way message consumer

  • @author: syske

  • @create: 2021-03-09 20:30

    / public class OnewayProducer {public static void main(String[] args) throws Exception{// Instantiate the Producer DefaultMQProducer producer = new DefaultMQProducer(“please_rename_unique_group_name”); // Set the address of NameServer (producer.setNamesrvaddr (“localhost:9876”)); // Start Producer instance producer.start(); for (int i = 0; i < 100; I++) {mailto:br/% 3esendresult.getmsgid ()); %3Cbr/%3E%7D%3Cbr/%3E@Override%3Cbr/)