1、下载安装

 

http://rocketmq.apache.org

下载编译好的zip包,解压即可

2、启动运行

在bin目录下运行mqnamesrv程序

 ./mqnamesrv

运行mqbroker

 ./mqbroker -n localhost:9876

这里的mqnamesrv启动端口默认是9876。这个是硬编码写在代码里面的。

 

org.apache.rocketmq.namesrv.NamesrvStartup文件中找到一下代码

 

final NettyServerConfig nettyServerConfig = new NettyServerConfig();
        nettyServerConfig.setListenPort(9876);
        if (commandLine.hasOption('c')) {
            String file = commandLine.getOptionValue('c');
            if (file != null) {
                InputStream in = new BufferedInputStream(new FileInputStream(file));
                properties = new Properties();
                properties.load(in);
                MixAll.properties2Object(properties, namesrvConfig);
                MixAll.properties2Object(properties, nettyServerConfig);
                namesrvConfig.setConfigStorePath(file);
                System.out.printf("load config properties file OK, %s%n", file);
                in.close();
            }
        }

 

比较有意思的,是居然是吧端口直接写在代码里面,而不是从配置文件里面读取的。另外在下面在判断启动命令中是否有c命令,如果有,加载指定的配置文件,通过反射设置对应的属性。

或者是直接直接在启动命令行去增加参数

通过以下代码实现

MixAll.properties2Object(ServerUtil.commandLine2Properties(commandLine), namesrvConfig);

 

不仅仅mqnamesrv的代码是这样实现的,我们可以看到broker也是这么干吗,先硬编码一个端口10911,然后在检查启动指定的配置文件,这种做法也是常见的。

  • 测试消息生产:

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

  • 测试消息消费

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

  • Rocketmq有哪些角色

1>、namesrv: 用作服务发现,连接broker,producer,consumer

2>、broker: mq的本身,消息的生产和消费都通过broker完成

3>、producer:消息的生产者

4>、consumer:消息的消费者

  • 消费方式

1>、集群模式:

broker把消息发送给consumer集群,每个消息只能被消费一次

2>、广播模式:

每条消息都会被订阅的consumer消费。

  • java实现消息的发送:

1>单条发送send

2>批量发送 send

3>异步发送sendCallback

4>只管发送,,不管结果sendOneWay

不难理解这几个定义,就如同字面含义一样的,在速度方面4>3>2>1,因为4不需要知道结果,只管发送,不管成功鬼使白,3异步发送按照正常理解肯定比同步要快,2批量肯定咋速度上要大于单条发送。

 

6 对 “RocketMQ(一)初步认识”的想法;

  1. Magnificent goods from you, man. I’ve take into accout your stuff prior to
    and you are just too excellent. I really like
    what you have received right here, really like what you’re saying and the way in which during which you assert it.
    You’re making it enjoyable and you still take care of to
    stay it wise. I cant wait to learn much more from you.
    That is really a great web site.

    Also visit my webpage :: CBD for dogs

  2. Heya exceptional website! Does running a blog such as this require a lot of work?
    I’ve no expertise in computer programming but I had been hoping to start my own blog soon. Anyway, should you
    have any ideas or techniques for new blog owners please share.
    I understand this is off topic nevertheless I just had to ask.
    Kudos!

发表评论

电子邮件地址不会被公开。