针对dockerized&amp ;;验证dockerized Spring Boot应用程序链接ActiveMQ

时间:2015-04-17 16:02:19

标签: spring docker spring-boot activemq

我正在启动我的activemq容器,如下所示:

docker run -p 61616:61616 -p 8161:8161 --name='activemq' -d \
-e 'ACTIVEMQ_LOGLEVEL=DEBUG' \
-e 'ACTIVEMQ_ADMIN_USER=bot' \
-e 'ACTIVEMQ_ADMIN_PASSWORD=blahblah' \
-e 'ACTIVEMQ_OWNER_LOGIN=bot' \
-e 'ACTIVEMQ_OWNER_PASSWORD=blahblah' \
-e 'ACTIVEMQ_JMX_LOGIN=bot' \
-e 'ACTIVEMQ_JMX_PASSWORD=blahblah' \
-v /data/activemq:/data/activemq \
-v /var/log/activemq:/var/log/activemq \
webcenter/activemq:latest

我的应用的application.yml具有以下内容:

spring:
  activemq:
    broker-url: ${ACTIVEMQ_PORT_61616_TCP}
    user: bot
    password: blahblah

我正在启动我的应用容器:

docker run --name='myapp' \
-w /app/ -v /home/ubuntu/myapp/logs:/app/logs \
-v /home/ubuntu/myapp/config:/app/config \
-v /tmp:/tmp -p 4980:4980 \
--link activemq:activemq \
-d myapp

请注意,我将我的应用程序的容器与activemq容器相关联。

最后,当我尝试从我的应用程序发送一个msg到activeMQ时(通过Camel路线 - 但我不认为这是相关的),我在日志中看到了这一点:

javax.jms.JMSSecurityException: User name [bot] or password is invalid.
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:52)
    at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1417)
    at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1522)
    at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:527)
    at org.springframework.jms.listener.AbstractJmsListeningContainer.refreshSharedConnection(AbstractJmsListeningContainer.java:400)
    at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:907)
    at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:882)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1053)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.SecurityException: User name [bot] or password is invalid.
    at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:80)
    at org.apache.activemq.broker.BrokerFilter.addConnection(BrokerFilter.java:92)
    at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:97)
    at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:764)
    at org.apache.activemq.broker.jmx.ManagedTransportConnection.processAddConnection(ManagedTransportConnection.java:79)
    at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)
    at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:294)
    at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:148)
    at org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)
    at org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:113)
    at org.apache.activemq.transport.AbstractInactivityMonitor.onCommand(AbstractInactivityMonitor.java:270)
    at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:83)
    at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:214)
    at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:196)
    ... 1 common frames omitted
Caused by: javax.security.auth.login.LoginException: No LoginModules configured for activemq-domain
    at javax.security.auth.login.LoginContext.init(LoginContext.java:264)
    at javax.security.auth.login.LoginContext.<init>(LoginContext.java:417)
    at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:72)
    ... 14 common frames omitted

毋庸置疑,这一切都是有效的。在我的开发机器上本地运行这些组件(即没有停靠)。只是不在EC2实例上的docker容器内工作。

任何和所有帮助表示赞赏!

感谢。

2 个答案:

答案 0 :(得分:2)

我最终通过自定义docker镜像来实现它,如下所示:

  1. 克隆git repo:git clone https://github.com/disaster37/activemq.git

  2. 修复此文件中传递给curl的网址:assets/setup/install (该文件中的当前网址不再有效)

  3. 修改此文件:assets/config/activemq.xml并将<jaasAuthenticationPlugin><authorizationPlugin>元素替换为:

  4. <simpleAuthenticationPlugin anonymousAccessAllowed="false"> <users> <authenticationUser username="system" password="blubblub" groups="users,admins"/> <authenticationUser username="bot" password="blahblah" groups="users"/> </users> </simpleAuthenticationPlugin>

    1. 构建我自己的泊坞窗图片:docker build --tag="zackattack/activemq"

    2. 运行它:docker logs -f $(docker run --name='activemq' -d zackattack/activemq)

    3. 它不漂亮 - 但它有效!

答案 1 :(得分:0)

判断我可以从调试日志中收集到什么。首先,调试日志显示&#39; bot&#39;正在越过(名称),因此,myapp和activemq之间似乎存在连接。所以联系正在发挥作用。我的线索是:

Caused by: javax.security.auth.login.LoginException: No LoginModules configured for activemq-domain

我不知道登录模块是什么,但是,我猜想你需要告诉activemq如何处理它收到的名称/密码?查看有关activemq的docker hub的描述,有一个例子:

-e 'ACTIVEMQ_READ_LOGIN=consumer_login' -e 'ACTIVEMQ_READ_PASSWORD=consumer_password'\

-e 'ACTIVEMQ_STATIC_TOPICS=topic1;topic2;topic3' -e 'ACTIVEMQ_STATIC_QUEUES=queue1;queue2;queue3'

是否可能需要这些设置中的任何一个来配置activemq-domain登录模块?或者是在某个配置文件中完成的?从码头的角度来看,我认为一切都井然有序。我认为activemq存在配置问题。当这在常规环境中有效时,如何启动activemq(命令行参数,环境变量和配置文件是什么)?