zoukankan      html  css  js  c++  java
  • ActiveMQ配置用户认证信息

    以 apache-activemq-5.15.13-bin.tar.gz (从清华镜像 下载 )为例,编辑activemq.xml

    在 <broker> 节点内增如下xml片段:

    <plugins>
        <simpleAuthenticationPlugin>
            <users>
                <authenticationUser username="${activemq.username}" password="${activemq.password}" groups="users, admins" />
            </users>
        </simpleAuthenticationPlugin>
    </plugins>

    查看 credentials.properties 可以发现其内容如下:

    ## ---------------------------------------------------------------------------
    ## Licensed to the Apache Software Foundation (ASF) under one or more
    ## contributor license agreements.  See the NOTICE file distributed with
    ## this work for additional information regarding copyright ownership.
    ## The ASF licenses this file to You under the Apache License, Version 2.0
    ## (the "License"); you may not use this file except in compliance with
    ## the License.  You may obtain a copy of the License at
    ## 
    ## http://www.apache.org/licenses/LICENSE-2.0
    ## 
    ## Unless required by applicable law or agreed to in writing, software
    ## distributed under the License is distributed on an "AS IS" BASIS,
    ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    ## See the License for the specific language governing permissions and
    ## limitations under the License.
    ## ---------------------------------------------------------------------------
    
    # Defines credentials that will be used by components (like web console) to access the broker
    
    activemq.username=system
    activemq.password=manager
    guest.password=password

    标红的地方则为账户密码

    编辑 jetty-realm.properties 配置文件,在最后一行新增 system: manager, admin,如下标红所示

    ## ---------------------------------------------------------------------------
    ## Licensed to the Apache Software Foundation (ASF) under one or more
    ## contributor license agreements.  See the NOTICE file distributed with
    ## this work for additional information regarding copyright ownership.
    ## The ASF licenses this file to You under the Apache License, Version 2.0
    ## (the "License"); you may not use this file except in compliance with
    ## the License.  You may obtain a copy of the License at
    ## 
    ## http://www.apache.org/licenses/LICENSE-2.0
    ## 
    ## Unless required by applicable law or agreed to in writing, software
    ## distributed under the License is distributed on an "AS IS" BASIS,
    ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    ## See the License for the specific language governing permissions and
    ## limitations under the License.
    ## ---------------------------------------------------------------------------
    
    # Defines users that can access the web (console, demo, etc.)
    # username: password [,rolename ...]
    admin: admin, admin
    user: user, user
    system: manager, admin

    请保持两个 properties 配置文件中的账户密码配置一致,如需修改请同时修改两个配置文件

    重启activemq生效

    curl验证

    curl -u system:manager --data-urlencode "body=$(date)" http://localhost:8161/api/message/wangrui-queue?type=queue

    代码修改:

    在定义activemq连接池的时候添加用户密码信息即可,示例如下:(代码中使用的消息服务器使用的是自定义的账户密码)

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
    
    <beans>
        <!-- 配置生产者连接池 -->
        <bean id="producerConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
            destroy-method="stop">
            <property name="connectionFactory">
                <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                    <property name="brokerURL">
                        <value>${activemq.url}</value>
                    </property>
                    <property name="userName">
                        <value>gfstack</value>
                    </property>
                    <property name="password">
                        <value>gfstack</value>
                    </property>
                </bean>
            </property>
            <property name="maxConnections" value="${producer.maxConnections}"></property>
            <property name="maximumActiveSessionPerConnection" value="${producer.maximumActiveSessionPerConnection}"></property>
            <property name="idleTimeout" value="${producer.idleTimeout}"></property>
        </bean>
        
        <!-- 配置消费者连接池 -->
        <bean id="consumerConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory"
            destroy-method="stop">
            <property name="connectionFactory">
                <bean class="org.apache.activemq.ActiveMQConnectionFactory">
                    <property name="brokerURL">
                        <value>${activemq.url}</value>
                    </property>
                    <property name="userName">
                        <value>gfstack</value>
                    </property>
                    <property name="password">
                        <value>gfstack</value>
                    </property>
                </bean>
            </property>
            <property name="maxConnections" value="${consumer.maxConnections}"></property>
            <property name="maximumActiveSessionPerConnection" value="${consumer.maximumActiveSessionPerConnection}"></property>
            <property name="idleTimeout" value="${consumer.idleTimeout}"></property>
        </bean>
    </beans>
  • 相关阅读:
    JS(JQEERY) 获取JSON对象中的KEY VALUE
    .NET 日期数据的格式化方法
    jquery转换json对象为字符串
    Repeater和Gridview前台显示行号的方法
    Asp.Net对Json字符串的解析和应用
    C++学习之路—运算符重载(一)概念、方法及规则
    C++学习之路—多态性与虚函数(二)纯虚函数与抽象类
    C++学习之路—多态性与虚函数(一)利用虚函数实现动态多态性
    软件工程师的优秀品质
    C++学习之路—继承与派生(四)拓展与总结
  • 原文地址:https://www.cnblogs.com/nihaorz/p/13030428.html
Copyright © 2011-2022 走看看