关于 ActiveMQ

今天玩了下 ActiveMQ,希望实现服务器的消息可以通知到各个客户终端。

安装:

1、安装 ActiveMQ 之前必须安装 Java 的 jdk , 可以从此下载:   http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2、安装完 jdk 后,必须重新设置下环境变量,主要几个:

     1)创建环境变量:JAVA_HOME, 值是 jdk 的安装路径,例如:C:Program FilesJavajdk1.8.0_91

     2)创建环境变量:classpath , 值是   .;%JAVA_HOME%libdt.jar;%JAVA_HOME%lib ools.jar    这是为了在开发时能找到可用的包

     3)设置 path, 增加安装路径下的 bin 目录,例如: C:Program FilesJavajdk1.8.0_91in

3、然后到 ActiveMQ 的解压目录下的 bin 下,用 dos 下运行,或者做个批处理: activemq start

     有两种启动方式,还有一种 activemq console

     ps: 老版本只需要直接运行 activemq.bat 就可以, 不带参, 我用的是最新的 ActiveMQ 5.13.3 Release

4、运行后,可以直接用 运行服务器地址的 8161 端口验证, 例如: http://127.0.0.1:8161  , 默认登录密码是 admin / admin .   注意通过 conf/jetty-realm.properties 修改登录用户名和密码. conf/jetty.xml 修改 8161 端口

5、ActiveMQ 启动后,默认的连接端口是  81816, 连接没有安全认证,就是说知道 ip 和端口就可以连上去

认证配置:

安全认证目前知道有两种,一种简单的方式:

在conf/activemq.xml文件中加入以下内容即可:

<plugins>
<!-- Configure authentication; Username, passwords and groups -->
<simpleAuthenticationPlugin>
<users>
    <authenticationUser username="system" password="${activemq.password}"   groups="users,admins"/>
    <authenticationUser username="user" password="${guest.password}"  groups="users"/>
    <authenticationUser username="guest" password="${guest.password}" groups="guests"/>
</users>
</simpleAuthenticationPlugin>
</plugins>

此方法配置中的占位符的值可在conf/credentials.properties 设置

注意:按照官网资料http://activemq.apache.org/xml-reference.html  

【To avoid this XML validation error in ActiveMQ 5.4/5.5, simply change the ordering of the XML elements so that they are in alphabetical order。】此配置文件中是按英文字母顺序排列。所以<plugins><plugins/>必须放在<systemUsage>与<managementContext>之间

groups.propert  文件定义了组下面的用户。users.properties 文件定义了用户名对应的密码

还有一种方法看似更高级,没有尝试:

在conf/activemq.xml文件中加上

<plugins>
    <!--use JAAS to authenticate using the login.config file on the classpath to configure JAAS -->
    <jaasAuthenticationPlugin configuration="activemq-domain" />
    <!--  lets configure a destination based authorization mechanism -->
    <authorizationPlugin>
        <map>
            <authorizationMap>
                <authorizationEntries>

                <!-->表示通配符,例如USERS.>表示以USERS.开头的主题,>表示所有主题,read表示读的权限,write表示写的权限,admin表示角色组-->
                    <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
                    <authorizationEntry topic=">" read="admins" write="admins" admin="admins" />
                    <authorizationEntry queue="ActiveMQ.Advisory.>" read="admins" write="admins" admin="admins" />
                    <authorizationEntry topic="ActiveMQ.Advisory.>" read="admins" write="admins" admin="admins" />
                </authorizationEntries>
            </authorizationMap>
        </map>
    </authorizationPlugin>
</plugins>

b)在conf目录下增加login.config,groups.properties,users.properties

login.config 内容如下:

activemq-domain {
        org.apache.activemq.jaas.PropertiesLoginModule required
        debug=true
        org.apache.activemq.jaas.properties.user="users.properties"
        org.apache.activemq.jaas.properties.group="groups.properties";
    };

groups.properties  内容如下:

    #group=userName
   admins=system

users.properties  内容如下:

   #userName=password
   system=manager
原文地址:https://www.cnblogs.com/zhenfei/p/5491655.html