第 4 章 创建独立代理

您可以通过在本地机器上创建独立代理实例,启动它,并生成和使用一些测试信息来快速使用 AMQ Broker。

先决条件

4.1. 创建代理实例

代理实例是一个目录,其中包含代理的配置和运行时数据。要创建新的代理实例,您首先为 broker 实例创建一个目录,然后使用 artemis create 命令创建代理实例。

此流程演示了如何在本地机器中创建简单独立代理。代理使用基本的默认配置,并接受使用任何受支持的消息传递协议来自客户端的连接。

流程

  1. 为 broker 实例创建一个目录。

    如果使用…​这些以下操作

    Red Hat Enterprise Linux

    1. 创建一个新目录,以用作 broker 实例的位置。

      $ sudo mkdir /var/opt/amq-broker
    2. 分配安装期间创建的用户。

      $ sudo chown -R amq-broker:amq-broker /var/opt/amq-broker

    Windows

    使用 Windows Explorer 创建一个新文件夹,以用作代理实例的位置。

  2. 使用 artemis create 命令创建代理。

    如果使用…​这些以下操作

    Red Hat Enterprise Linux

    1. 切换到安装期间创建的用户帐户。

      $ su - amq-broker
    2. 更改到您刚才为代理实例创建的目录。

      $ cd /var/opt/amq-broker
    3. 从 broker 实例的目录中,创建 broker 实例。

      $ <install_dir>/bin/artemis create mybroker

    Windows

    1. 从您刚才为代理实例创建的目录打开命令提示符。
    2. 从 broker 实例的目录中,创建 broker 实例。

      > <install_dir>\bin\artemis.cmd create mybroker
  3. 按照 artemis create 提示来配置代理实例。

    例 4.1. 使用 artemis create 配置代理实例

    $ /opt/redhat/amq-broker/bin/artemis create mybroker
    
    Creating ActiveMQ Artemis instance at: /var/opt/amq-broker/mybroker
    
    --user: is mandatory with this configuration:
    Please provide the default username:
    admin
    
    --password: is mandatory with this configuration:
    Please provide the default password:
    
    --role: is mandatory with this configuration:
    Please provide the default role:
    amq
    
    --allow-anonymous | --require-login: is mandatory with this configuration:
    Allow anonymous access? (Y/N):
    Y
    
    Auto tuning journal ...
    done! Your system can make 19.23 writes per millisecond, your journal-buffer-timeout will be 52000
    
    You can now start the broker by executing:
    
    "/var/opt/amq-broker/mybroker/bin/artemis" run
    
    Or you can run the broker in the background using:
    
    "/var/opt/amq-broker/mybroker/bin/artemis-service" start