ActiveMQ -- softwbc 发布于:2017年11月29日 浏览量:5331  |

ActiveMQ(号称开源用的最多的)官网:http://activemq.apache.org/index.html,Apache出品的,最流行的,能力最强劲的开源消息总线,是一个完全支持JMS1.1J2EE 1.4规范的 JMS Provider实现。

ActiveMQ特性:

1、支持多种语言和协议编写客户端;

2、完全支持 JMS1.1J2EE1.4规范;

3、支持与Spring集成,可以很容易的嵌入到使用Spring的系统里;Spring集成后,可以直接适用当前公司服务化治理方案的核心框架DUBBO,若要将队列发送、队列接收、发布的服务接口公开为DUBBO接口。

4、支持多种传送协议in-VM,TCP,SSL,NIO,UDP,JGroups,JXTA;

5、支持通过JDBCjournal提供高速的消息持久化;

6、提供了一个监控管理控制台;

7Apache下开源项目,非常活跃,相关资料文档较多


相关问题解决



1、控制台无法查看队列信息,并且报错如下图:

2015-03-04 18:32:20,019 | INFO  | Connector vm://localhost started | org.apache.activemq.broker.TransportConnector | qtp189236502-95
2015-03-04 18:32:20,029 | WARN  | Failed to add Connection ID:yz-c028-17-18-83.50-58653-1425464891289-7:1 | org.apache.activemq.broker.TransportConnection | ActiveMQ VMTransport: vm://localhost#3-1
java.lang.SecurityException: User name [system] or password is invalid.
        at org.apache.activemq.security.JaasAuthenticationBroker.addConnection(JaasAuthenticationBroker.java:80)[activemq-broker-5.11.1.jar:5.11.1]
        at org.apache.activemq.broker.BrokerFilter.addConnection(BrokerFilter.java:97)[activemq-broker-5.11.1.jar:5.11.1]
        at org.apache.activemq.broker.MutableBrokerFilter.addConnection(MutableBrokerFilter.java:102)[activemq-broker-5.11.1.jar:5.11.1]
        at org.apache.activemq.broker.TransportConnection.processAddConnection(TransportConnection.java:809)[activemq-broker-5.11.1.jar:5.11.1]
        at org.apache.activemq.command.ConnectionInfo.visit(ConnectionInfo.java:139)[activemq-client-5.11.1.jar:5.11.1]
        at org.apache.activemq.broker.TransportConnection.service(TransportConnection.java:334)[activemq-broker-5.11.1.jar:5.11.1]
        at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:188)[activemq-broker-5.11.1.jar:5.11.1]
        at org.apache.activemq.transport.ResponseCorrelator.onCommand(ResponseCorrelator.java:116)[activemq-client-5.11.1.jar:5.11.1]
        at org.apache.activemq.transport.MutexTransport.onCommand(MutexTransport.java:50)[activemq-client-5.11.1.jar:5.11.1]
        at org.apache.activemq.transport.vm.VMTransport.iterate(VMTransport.java:248)[activemq-broker-5.11.1.jar:5.11.1]
        at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:133)[activemq-client-5.11.1.jar:5.11.1]
        at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:48)[activemq-client-5.11.1.jar:5.11.1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_45]
        at java.lang.Thread.run(Thread.java:744)[:1.7.0_45]
2015-03-04 18:32:20,034 | WARN  | Security Error occurred: User name [system] or password is invalid. | org.apache.activemq.broker.TransportConnection.Service | ActiveMQ VMTransport: vm://localhost#3-1
2015-03-04 18:32:20,044 | INFO  | Connector vm://localhost stopped | org.apache.activemq.broker.TransportConnector | ActiveMQ Connection Executor: vm://localhost#2
2015-03-04 18:32:20,045 | WARN  |  | org.eclipse.jetty.servlet.ServletHandler | qtp189236502-95
org.apache.jasper.JasperException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'queueBrowser' defined in ServletContext resource [/WEB-INF/webconsole-query.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.activemq.web.QueueBrowseQuery]: Constructor threw exception; nested exception is javax.jms.JMSSecurityException: User name [system] or password is invalid.
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:418)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)[geronimo-servlet_3.0_spec-1.0.jar:1.0]
        at org.eclipse.jetty.servlet.JspPropertyGroupServlet.service(JspPropertyGroupServlet.java:132)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1496)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)[spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)[spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1484)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.apache.activemq.web.SessionFilter.doFilter(SessionFilter.java:45)[activemq-web-5.11.1.jar:5.11.1]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1484)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.apache.activemq.web.filter.ApplicationContextFilter.doFilter(ApplicationContextFilter.java:102)[file:/data/activemq-02-5.11.1/webapps/admin/WEB-INF/classes/:]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1476)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:522)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:522)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.Server.handle(Server.java:370)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at java.lang.Thread.run(Thread.java:744)[:1.7.0_45]
2015-03-04 18:32:20,056 | WARN  | /admin/browse.jsp | org.eclipse.jetty.servlet.ServletHandler | qtp189236502-95
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'queueBrowser' defined in ServletContext resource [/WEB-INF/webconsole-query.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.activemq.web.QueueBrowseQuery]: Constructor threw exception; nested exception is javax.jms.JMSSecurityException: User name [system] or password is invalid.
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:285)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1077)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:981)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:331)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.web.context.request.AbstractRequestAttributesScope.get(AbstractRequestAttributesScope.java:43)[spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:327)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1119)[spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.apache.activemq.web.filter.ApplicationContextFilter$2.get(ApplicationContextFilter.java:178)[file:/data/activemq-02-5.11.1/webapps/admin/WEB-INF/classes/:]
        at javax.el.MapELResolver.getValue(MapELResolver.java:196)[jsp-api-2.1-glassfish-2.1.v20100127.jar:]
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)[jsp-api-2.1-glassfish-2.1.v20100127.jar:]
        at com.sun.el.parser.AstValue.getValue(AstValue.java:138)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at com.sun.el.parser.AstDynamicExpression.getValue(AstDynamicExpression.java:59)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at com.sun.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:64)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:206)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1001)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at org.apache.jsp.browse_jsp._jspx_meth_c_set_0(org.apache.jsp.browse_jsp:352)
        at org.apache.jsp.browse_jsp._jspService(org.apache.jsp.browse_jsp:97)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)[geronimo-servlet_3.0_spec-1.0.jar:1.0]
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:389)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:486)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:380)[jsp-2.1-glassfish-2.1.v20100127.jar:]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)[geronimo-servlet_3.0_spec-1.0.jar:1.0]
        at org.eclipse.jetty.servlet.JspPropertyGroupServlet.service(JspPropertyGroupServlet.java:132)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1496)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)[spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)[spring-web-3.2.11.RELEASE.jar:3.2.11.RELEASE]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1484)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.apache.activemq.web.SessionFilter.doFilter(SessionFilter.java:45)[activemq-web-5.11.1.jar:5.11.1]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1484)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.apache.activemq.web.filter.ApplicationContextFilter.doFilter(ApplicationContextFilter.java:102)[file:/data/activemq-02-5.11.1/webapps/admin/WEB-INF/classes/:]
        at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1476)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:522)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:522)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.Server.handle(Server.java:370)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[jetty-all-8.1.16.v20140903.jar:8.1.16.v20140903]
        at java.lang.Thread.run(Thread.java:744)[:1.7.0_45]
2015-03-04 18:32:22,034 | INFO  | Stopping vm://localhost#2 because Failed with SecurityException: User name [system] or password is invalid. | org.apach

原因及解决:
JAAS权限问题,用户密码需要配置,修改credentials.properties,修改用户名密码


2、 ActiveMQ主备+Cluster方式高可用配置,服务器CPU占用率过高(16核服务器,CPU高达1300%)
研究后发现:
1、此问题在ActiveMQ服务启动后就已出现,此时并没有任何Consumer和Producter;
2、问题在于:

<networkConnectors>
        <networkConnector uri="masterslave:(tcp://ip1:61616,tcp://ip2:61617)" userName="admin" password="xxx" duplex="false" />
</networkConnectors>

修改为如下配置问题解决:

<networkConnectors>
         <networkConnector name="linkToCluster1" uri="masterslave:(tcp://ip1:61616,tcp://ip2:61617)?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600" userName="admin" password="xxx" duplex="true" />
</networkConnectors>

添加到参数说明(来自官网):

maximumConnections

Integer.MAX_VALUE

The maximum number of sockets the broker is allowed to create

wireFormat.*


All the properties with this prefix are used to configure the wireFormat. See Configuring Wire Formats for more information


name

bridge

name of the network - for more than one network connector between the same two brokers - use different names

3、错误

[org.apache.activemq.ActiveMQConnection]-[WARN] Async exception with no exception listener: org.apache.activemq.transport.InactivityIOException: Channel was inactive for too long: localhost/127.0.0.1:61616

ActiveMQ的tcp url:tcp://localhost:61616后面要加入?wireFormat.maxInactivityDuration=0 这样的参数,否则当一段时间没有消息发送时会抛出 "Channel was inactive for too long"异常



性能调优



性能优化

1、设置JVM内存参数:
在bin/env中修改参数(默认1G):

# Set jvm memory configuration (minimal/maximum amount of memory)

ACTIVEMQ_OPTS_MEMORY="-Xms512M -Xmx1G"


2、broker配置中的系统内存和磁盘空间使用量

         <systemUsage>

            <systemUsage>

                <memoryUsage>

                    <memoryUsagelimit="64 mb"/>

                </memoryUsage>

                <storeUsage>

                    <storeUsagelimit="100 gb"/>

                </storeUsage>

                <tempUsage>

                    <tempUsagelimit="50 gb"/>

                </tempUsage>

            </systemUsage>

        </systemUsage>

如果是嵌入式(embedded)方式使用的话,可以new一个SystemUsage来添加到BrokerService中去。这里配置的memoryUsage一定要小于jvm中设置的数量。

5.9.0版本,如果设置的 memoryUsagelimit大于实际可用java heap size值,比如默认启动 xmx=1G,那么实际的java heap size大概是910M,

则broker启动时会log.error提示设置内存出错,然后强制使用实际java heap size* 70% = 637M作为memoryUsagelimit。


3、splitSystemUsageForProducersConsumers导致消费缓慢甚至无法消费的问题

其实broker中还可以单独配置生产者使用的producerSystemUsage 和消费者使用的consumerSystemUsage,格式跟systeUsage一样。

默认情况下,没有配置producerSystemUsage 和 consumerSystemUsage,则生产者和消费者都使用systemUsage。

这时可能会因为生产者线程把内存用完,导致消费者线程处理缓慢甚至无法消费的问题。这种情况下,添加消费端的机器和消费者数量可能都无法增加消费的速度。

解决办法就是:

在broker上设置splitSystemUsageForProducersConsumers=”true”,使得生产者线程和消费者线程各使用各的内存。

默认是 生产者线程内存:消费者线程内存 = 6:4。

也可以通过如下两个参数设置生产者线程内存和消费者线程内存各一半:

producerSystemUsagePortion = 50

consumerSystemUsagePortion = 50

 

4、生产者流控

从5.x版本起,可以给每个producer单独设置流控。流控简单的说就是控制生产者的在内存使用限制下的行为。当然,流控的目的在于防止在将ActiveMQ作为内存MQ使用时,生产速度大于消费速度时将MQ撑爆的问题。

分两个情况:

1、 同步发送消息(useAsynSend为false):此时将在SystemUsage的限制下,使用destinationPolicy中的policyEntry中的限制,例如:

<destinationPolicy>

  <policyMap>

    <policyEntries>

      <policyEntry queue="queueA"producerFlowControl="true"memoryLimit="1mb">   

  <pendingQueuePolicy>

    <vmQueueCursor/>

  </pendingQueuePolicy>

</policyEntry>

    </policyEntries>

  </policyMap>

</destinationPolicy>

限制非持久化时queueA 的内存使用量为1mb,达到这个内存使用量时直接阻塞掉producer,直到有空余的内存时,才允许producer发送消息。

也可通过在systemUsage配置上设置sendFailIfNoSpace="true"或 sendFailIfNoSpaceAfterTimeout="3000"来控制客户端异常和等待时间。

 

异步发送时,由于不阻塞生产者,

可以通过connctionFactory.setProducerWindowSize(1024000);

来控制broker确认收到消息前生产者能发送的最大数据量(字节)。


5、消费者流控

消费者端,一般来说消费的越快越好,broker的积压越小越好。

但是考虑到事务性和客户端确认的情况,如果一个消费者一次获取到了很多消息却都不确认,这会造成事务上下文变大,broker端这种“半消费状态”的数据变多,所以ActiveMQ有一个prefetchSize参数来控制未确认情况下,最多可以预获取多少条记录。

默认情况如下:

持久化queue:1000条

非持久化queue: 1000条

持久化topic:100条

非持久化topic: 无限制

可以通过3中方式设置prefetchSize

1、  tcp://localhost:61616?jms.prefetchPolicy.all=50

2、  tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=1

3、  queue = new ActiveMQQueue("TEST.QUEUE?consumer.prefetchSize=10");


===============官方文档配置===============

Failover Transport Options

Option Name

Default

Description

transport.timeout

-1

Time that a send operation blocks before failing.

transport.initialReconnectDelay

10

Time in Milliseconds that the transport waits before attempting to reconnect the first time.

transport.maxReconnectDelay

30000

The max time in Milliseconds that the transport will wait before attempting to reconnect.

transport.backOffMultiplier

2

The amount by which the reconnect delay will be multiplied by if useExponentialBackOff is enabled.

transport.useExponentialBackOff

true

Should the delay between connection attempt grow on each try up to the max reconnect delay.

transport.randomize

true

Should the Uri to connect to be chosen at random from the list of available Uris.

transport.maxReconnectAttempts

0

Maximum number of time the transport will attempt to reconnect before failing (0 means infinite retries)

transport.startupMaxReconnectAttempts

0

Maximum number of time the transport will attempt to reconnect before failing when there has never been a connection made. (0 means infinite retries)(included in NMS.ActiveMQ v1.5.0+)

transport.reconnectDelay

10

The delay in milliseconds that the transport waits before attempting a reconnection.

transport.backup

false

Should the Failover transport maintain hot backups.

transport.backupPoolSize

1

If enabled, how many hot backup connections are made.

transport.trackMessages

false

keep a cache of in-flight messages that will flushed to a broker on reconnect

transport.maxCacheSize

256

Number of messages that are cached if trackMessages is enabled.

transport.updateURIsSupported

true

Update the list of known brokers based on BrokerInfo messages sent to the client.



Connection Options

Option Name

Default

Description

connection.AsyncSend

false

Are message sent Asynchronously.

connection.AsyncClose

true

Should the close command be sent Asynchronously

connection.AlwaysSyncSend

false

Causes all messages a Producer sends to be sent Asynchronously.

connection.CopyMessageOnSend

true

Copies the Message objects a Producer sends so that the client can reuse Message objects without affecting an in-flight message.

connection.ProducerWindowSize

0

The ProducerWindowSize is the maximum number of bytes in memory that a producer will transmit to a broker before waiting for acknowledgement messages from the broker that it has accepted the previously sent messages. In other words, this how you configure the producer flow control window that is used for async sends where the client is responsible for managing memory usage. The default value of 0 means no flow control at the client. See also Producer Flow Control

connection.useCompression

false

Should message bodies be compressed before being sent.

connection.sendAcksAsync

false

Should message acks be sent asynchronously

connection.messagePrioritySupported

true

Should messages be delivered to the client based on the value of the Message Priority header.

connection.dispatchAsync

false

Should the broker dispatch messages asynchronously to the connection's consumers.




OpenWire Options

Option Name

Default

Description

wireFormat.stackTraceEnabled

false

Should the stack trace of exception that occur on the broker be sent to the client? Only used by openwire protocol.

wireFormat.cacheEnabled

false

Should commonly repeated values be cached so that less marshalling occurs? Only used by openwire protocol.

wireFormat.tcpNoDelayEnabled

false

Does not affect the wire format, but provides a hint to the peer that TCP nodelay should be enabled on the communications Socket. Only used by openwire protocol.

wireFormat.sizePrefixDisabled

false

Should serialized messages include a payload length prefix? Only used by openwire protocol.

wireFormat.tightEncodingEnabled

false

Should wire size be optimized over CPU usage? Only used by the openwire protocol.

wireFormat.maxInactivityDuration

30000

The maximum inactivity duration (before which the socket is considered dead) in milliseconds. On some platforms it can take a long time for a socket to appear to die, so we allow the broker to kill connections if they are inactive for a period of time. Use by some transports to enable a keep alive heart beat feature. Set to a value <= 0 to disable inactivity monitoring.

maxInactivityDurationInitalDelay

10000

The initial delay in starting the maximum inactivity checks (and, yes, the word 'Inital' is supposed to be misspelled like that)




基于Jmeter的性能测试


说明:
测试平台:Core(TM) i7 3537U 2.0GHz 8G内存 固态存储 Windows10 
JMeter3.2 ActiveMQ5.13.3(由于相关版本迭代较快,使用不同版本中间件可能不完全适应)

一、ActiveMQ
此处我使用的是5.13.3源代码,在开发环境中启动:

一般使用二进制包,解压直接启动就行了

二、JMeter安装及配置
1、解压,apache-jmeter-3.2,磁盘路径:D:\Program Files\apache-jmeter-3.2
2、配置环境变量:
创建JMETER_HOME如下:
D:\Program Files\apache-jmeter-3.2
CLASSPATH中添加如下:
;%JMETER_HOME\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar;%JMETER_HOME%\lib\logkit-2.0.jar;
3、拷贝ActiveMQ中activemq-all-5.13.3.jar到D:\Program Files\apache-jmeter-3.2\lib下
4、在bin下添加jndi.properties文件,内容如下

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory  
java.naming.provider.url = tcp://127.0.0.1:61616
connectionFactoryNames = connectionFactory
queue.PTP_Q = Queue.PTP
topic.PUBSUB_T= VirtualTopic.PUBSUB

参数说明:PTP_Q对应JNDI name Request queue;Queue.PTP是ActiveMQ的队列名(topic同理)
并执行命令打包配置:jar uf ApacheJMeter.jar jndi.properties(注意:如果修改了此文件,需要重新执行以使其生效)
至此环境配置完成
三、点对点测试
1、启动JMeter,添加测试计划并保存

2、添加线程组,调试的情况下可以先默认单线程并执行一次

3、添加Sampler,此处添加的是点对点模式

4、配置点对点测试用例,要跟jndi.properties参数相对应;另外如果单发送只添“JNDI name Request queue”,接收的话填写“JNDI name Receive queue”

5、配置完成可以添加一个图形结果或其他分析
=================================分割线===========================
6、Pub/Sub模式配置,首先添加Publish的Sampler

7、Subscriber


关于我们 |  广告服务 |  联系我们 |  网站声明

Copyright © 2015 - 2016 DISPACE.NET |  使用帮助 |  关于我们 |  投诉建议

京ICP备13033209号-2