Rocketmq mac/linux 安装笔记

从零手写实现 mq

Quick Start

quick start

需要

64位操作系统,最好是Linux/Unix/Mac;
64位JDK 1.6+;
Maven 3.x
Git
Screen

JDK

ruby 复制代码
houbinbindeMacBook-Pro:aliyun-ons-client-java houbinbin$ java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

下载和安装

  • 下载 RocketMQ

从这里下载:https://github.com/alibaba/RocketMQ/releases,当前版本标签为 3.5.8

shell 复制代码
$ ls
RocketMQ-3.5.8		RocketMQ-3.5.8.tar.gz
  • 安装
shell 复制代码
$ pwd
/Users/houbinbin/it/tools/rocketMQ/RocketMQ-3.5.8

$ bash install.sh
...

然后我们得到

less 复制代码
 To refactor, move this assembly into a child project and use the flag <useAllReactorProjects>true</useAllReactorProjects> in each moduleSet.
[INFO] Building tar: /Users/houbinbin/IT/tools/rocketMQ/RocketMQ-3.5.8/target/alibaba-rocketmq-broker.tar.gz
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] rocketmq-all 3.5.8 ................................. SUCCESS [ 48.565 s]
[INFO] rocketmq-remoting 3.5.8 ............................ SUCCESS [  1.772 s]
[INFO] rocketmq-common 3.5.8 .............................. SUCCESS [  1.348 s]
[INFO] rocketmq-client 3.5.8 .............................. SUCCESS [  1.522 s]
[INFO] rocketmq-store 3.5.8 ............................... SUCCESS [  0.815 s]
[INFO] rocketmq-srvutil 3.5.8 ............................. SUCCESS [  0.139 s]
[INFO] rocketmq-broker 3.5.8 .............................. SUCCESS [  0.951 s]
[INFO] rocketmq-tools 3.5.8 ............................... SUCCESS [  0.889 s]
[INFO] rocketmq-namesrv 3.5.8 ............................. SUCCESS [  0.373 s]
[INFO] rocketmq-example 3.5.8 ............................. SUCCESS [  0.392 s]
[INFO] rocketmq-filtersrv 3.5.8 ........................... SUCCESS [  0.337 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 59.323 s
[INFO] Finished at: 2017-01-02T18:21:01+08:00
[INFO] Final Memory: 52M/1042M
[INFO] ------------------------------------------------------------------------

环境配置

确保以下环境变量正确设置:JAVA_HOME

现在设置 ROCKETMQ_HOME 环境变量:

bash 复制代码
cd devenv

echo "ROCKETMQ_HOME=`pwd`" >> ~/.bash_profile

立即生效:

bash 复制代码
source ~/.bash_profile

启动 RocketMQ Name Server 和 Broker

确保在 devenv 目录下:

bash 复制代码
$ cd bin
$ pwd
/Users/houbinbin/it/tools/rocketMQ/RocketMQ-3.5.8/devenv/bin
  • 启动 Name Server

    screen bash mqnamesrv

现实是可能会遇到这个:

csharp 复制代码
$ screen bash mqnamesrv
[screen is terminating]

screen is terminating

执行以下命令(暂时提权):

su

使用 screen 命令进入, 运行:

ruby 复制代码
$   bash mqnamesrv

接下来

ini 复制代码
sh-3.2# bash mqnamesrv
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON

如果您看到 "The Name Server boot success. serializeType=JSON",这表示命名服务器已成功启动。

按下 Ctrl + A,然后按 D 分离会话。

csharp 复制代码
sh-3.2# screen
[detached]

Start Broker 启动 broker

ini 复制代码
sh-3.2# screen
sh-3.2# pwd
/Users/houbinbin/it/tools/rocketMQ/RocketMQ-3.5.8/devenv/bin
sh-3.2# bash mqbroker -n localhost:9876
cp: /var/root/rmq_bk_gc.log: No such file or directory
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file /var/root/tmpfs/logs/gc.log due to No such file or directory

The broker[houbinbindeMacBook-Pro.local, 192.168.2.102:10911] boot success. serializeType=JSON and name server is localhost:9876

如果您看到类似以下输出:

The broker[lizhanhui-Lenovo, 172.30.30.233:10911] boot success. serializeType=JSON and name server is localhost:9876,则您的 broker 已成功运行。

发送和接收消息

在发送/接收消息之前,我们需要告诉客户端名称服务器的位置。RocketMQ 提供了多种实现方式。 为简单起见,我们使用环境变量 NAMESRV_ADDR

ini 复制代码
$   export NAMESRV_ADDR=localhost:9876

本文由博客一文多发平台 OpenWrite 发布!

相关推荐
bing_1587 分钟前
Java 中求两个 List集合的交集元素
java·list
工业互联网专业26 分钟前
基于springboot+vue的高校社团管理系统的设计与实现
java·vue.js·spring boot·毕业设计·源码·课程设计
九圣残炎28 分钟前
【ElasticSearch】 Java API Client 7.17文档
java·elasticsearch·搜索引擎
m0_748251521 小时前
Ubuntu介绍、与centos的区别、基于VMware安装Ubuntu Server 22.04、配置远程连接、安装jdk+Tomcat
java·ubuntu·centos
Bro_cat2 小时前
深入浅出JSON:数据交换的轻量级解决方案
java·ajax·java-ee·json
等一场春雨2 小时前
Java设计模式 五 建造者模式 (Builder Pattern)
java·设计模式·建造者模式
hunzi_12 小时前
Java和PHP开发的商城系统区别
java·php
V+zmm101342 小时前
教育培训微信小程序ssm+论文源码调试讲解
java·数据库·微信小程序·小程序·毕业设计
十二同学啊2 小时前
Spring Boot 中的 InitializingBean:Bean 初始化背后的故事
java·spring boot·后端
我劝告了风*2 小时前
NIO | 什么是Java中的NIO —— 结合业务场景理解 NIO (二)
java·nio