Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the steps for Window to build and deploy RocketMQ

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

How Window builds and deploys RocketMQ steps, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Order

I've used ActiveMQ simply before, but I used RocketMQ on my company's project, so I'm going to spend more time on it and figure out how to configure the project.

After reading a lot of materials, I first talk about my own simple understanding of RocketMQ. Both the consumer and the producer we write belong to the client, and we need to install RocketMQ, which belongs to the server. Similar to ActivieMQ and zookeeper, the consumer, producer, and server (NameServer) are implemented in the observer mode.

Install RocketMQ on the operating system, start NameServer on the server, start Broker, write Consumer code, and run the consumer. Write Producer code and run the producer.

The basic simple logic is like this, and of course there are a lot of details. We usually use it on window during the test. We stepped on a bit of a hole and finished it successfully.

Installation and operation

1. Download

It is recommended to download the release version. I have tried to compile it myself, and I don't know why I reported it wrong.

Rocketmq-all-4.2.0-bin-release.zip

Decompress it as follows:

2. Start

NameServer

The system environment needs to be configured before startup, otherwise an error will be reported. Remember to restart the computer when the configuration is complete

Please set the ROCKETMQ_HOME variable in your environment!

System environment variable name: ROCKETMQ_HOME

Everyone is different, compare my path above-variable value: d:\ rocketMQ

Enter the window command window, go to the bin directory, and execute

Start mqnamesrv.cmd

As mentioned above, the NameServer starts successfully. Do not turn off the window during use.

Broker

Similarly, open a command window again, go to the bin directory, and type

Start mqbroker.cmd-n localhost:9876

The ip+port above is the process of NameServer, and because the Nameser installation starts locally, the ip here is localhost.

If you run the command above, the following error may be reported. The main class cannot be found or cannot be loaded

If this happens, open bin-- > runbroker.cmd and change% CLASSPATH% to

"" CLASSPATH% ""

Save and execute the above command again. After a successful execution, the window does not display anything, just an empty window that represents success.

Write code

Rely on RocketMQ

Org.apache.rocketmqrocketmq-client4.2.0

1 、 Consumer

Public class Consumer {public static void main (String [] args) throws MQClientException {/ / fill in the group name DefaultMQPushConsumer consumer = new DefaultMQPushConsumer ("my-group-name-A"); / / NameServer address consumer.setNamesrvAddr ("localhost:9876"); / / 1:topic name 2:tag name consumer.subscribe ("topic-name-A", "tag-name-A") Consumer.registerMessageListener (new MessageListenerConcurrently () {@ Overridepublic ConsumeConcurrentlyStatus consumeMessage (List msgs, ConsumeConcurrentlyContext context) {for (MessageExt msg: msgs) {System.out.println (new String (msg.getBody ());} return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;}}); consumer.start (); System.out.println ("Consumer Started!");}}

Run it first.

2 、 Producer

Pay attention to matching the corresponding parameters: group topic tag

Public class Producer {public static void main (String [] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {DefaultMQProducer producer = new DefaultMQProducer ("my-group-name-A"); producer.setNamesrvAddr ("localhost:9876"); producer.start (); Message message = new Message ("topic-name-A", "tag-name-A", "Message: My blog address guozh.net" .getBytes ()); producer.send (message); System.out.println ("Message sended"); producer.shutdown ();}}

Run producer again.

Then go to Consumer to see if you got the message.

Monitoring platform

Like other MQ, visual monitoring and Linux monitoring for Window versions are also provided here. You can see the details of message consumption, but in fact, in the actual development process, Window displays very little interface data and does not see much content. So the actual project is to look at the Linux data.

The project on our side is also deployed on Linux to see the MQ consumption.

But you can learn to expand the painting for the installation of Linux.

1. Download

Rocketmq-console

In fact, the method of installation and deployment is provided here, which can be based on the actual situation.

So step by step, modify the configuration file first. Modify the application.properties in the following location

Rocketmq-console\ src\ main\ resources

Mainly like the above two need to modify, the port of the platform deployment. I don't use 8080 here, so I use 8080 here. The following is the startup location of NameServer, which can be filled in according to your actual situation.

2. First of all, the above Tips also said to see if your Maven image belongs to Aliyun, otherwise you may not be able to download jar or very slow, needless to say here.

Enter the command window, go to the rocketmq-console directory, and execute.

Mvn clean package-Dmaven.test.skip=true

After the Build succeeds, execute it again

Java-jar target/rocketmq-console-ng-1.0.0.jar

When you are finished, just go to the URL. For example, this is localhost:8080.

Ok! Finished, it is estimated that later will be a good study of RocketMQ.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report