我有一个条件,我需要从队列中读取数据并相应地处理它。因此我为此目的使用apache-camel。
现在我的Camel配置如下:
的applicationContext.xml
<camel:camelContext id="camel-server">
<camel:package>com.sorc.processor.route</camel:package>
<camel:jmxAgent id="agent" createConnector="true" />
</camel:camelContext>
FeedProcessorRoute.java
public class FeedProcessorRoute extends RouteBuilder{
private @Value("${activemq_feed_observer_queue_name}") String activemqQueueName;
@Override
public void configure() throws Exception {
from("amq:" + activemqQueueName + "?exchangePattern=InOut&preserveMessageQos=true")
.routeId("id1") // Set the routeId to the class name. The routeId is printed when logging.
.process(this.feedProcessorTrigger)
.log("The FeedProcessor route has finished\n\n"));
}
FeedProcessorTrigger.java
public class FeedProcessorTrigger implements Processor{
@Override
public void process(Exchange exchange) throws Exception {
//I have added my processing logic here
}
}
当我在tomcat中部署我的战争时,我收到以下错误
15:06:24.602 [localhost-startStop-1] DEBUG o.a.c.c.j.DefaultJmsMessageListenerContainer - Could not establish shared JMS Connection - leaving it up to asynchronous invokers to establish a Connection as soon as possible
javax.jms.JMSException: Error while attempting to add new Connection to the pool
at org.apache.activemq.jms.pool.PooledConnectionFactory.createJmsException(PooledConnectionFactory.java:243) ~[activemq-jms-pool-5.9.1.jar:5.9.1]
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:198) ~[activemq-jms-pool-5.9.1.jar:5.9.1]
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:177) ~[activemq-jms-pool-5.9.1.jar:5.9.1]
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184) ~[spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:405) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractJmsListeningContainer.establishSharedConnection(AbstractJmsListeningContainer.java:373) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer.establishSharedConnection(DefaultMessageListenerContainer.java:765) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractJmsListeningContainer.doStart(AbstractJmsListeningContainer.java:280) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.AbstractJmsListeningContainer.start(AbstractJmsListeningContainer.java:265) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer.start(DefaultMessageListenerContainer.java:566) [spring-jms-3.2.8.RELEASE.jar:3.2.8.RELEASE]
at org.apache.camel.component.jms.JmsConsumer.startListenerContainer(JmsConsumer.java:105) [camel-jms-2.13.1.jar:2.13.1]
at org.apache.camel.component.jms.JmsConsumer.prepareAndStartListenerContainer(JmsConsumer.java:171) [camel-jms-2.13.1.jar:2.13.1]
at org.apache.camel.component.jms.JmsConsumer.doStart(JmsConsumer.java:155) [camel-jms-2.13.1.jar:2.13.1]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:2042) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:2336) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:2272) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:2202) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:1981) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1851) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1683) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1651) [camel-core-2.13.1.jar:2.13.1]
at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:254) [camel-spring-2.13.1.jar:2.13.1]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:120) [camel-spring-2.13.1.jar:2.13.1]
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:318) [camel-spring-2.13.1.jar:2.13.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151) [spring-context-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128) [spring-context-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:331) [spring-context-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:773) [spring-context-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483) [spring-context-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) [spring-web-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) [catalina.jar:7.0.54]
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) [catalina.jar:7.0.54]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) [catalina.jar:7.0.54]
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) [catalina.jar:7.0.54]
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) [catalina.jar:7.0.54]
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083) [catalina.jar:7.0.54]
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880) [catalina.jar:7.0.54]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_05]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [na:1.7.0_05]
at java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.7.0_05]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.7.0_05]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.7.0_05]
at java.lang.Thread.run(Thread.java:722) [na:1.7.0_05]
Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.SocketException: Permission denied: connect
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:358) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:303) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:243) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:251) ~[activemq-jms-pool-5.9.1.jar:5.9.1]
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:98) ~[activemq-jms-pool-5.9.1.jar:5.9.1]
at org.apache.activemq.jms.pool.PooledConnectionFactory$1.makeObject(PooledConnectionFactory.java:78) ~[activemq-jms-pool-5.9.1.jar:5.9.1]
at org.apache.commons.pool.impl.GenericKeyedObjectPool.addObject(GenericKeyedObjectPool.java:1748) ~[commons-pool-1.6.jar:1.6]
at org.apache.activemq.jms.pool.PooledConnectionFactory.createConnection(PooledConnectionFactory.java:196) ~[activemq-jms-pool-5.9.1.jar:5.9.1]
... 46 common frames omitted
Caused by: java.net.SocketException: Permission denied: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.7.0_05]
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:75) ~[na:1.7.0_05]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) ~[na:1.7.0_05]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) ~[na:1.7.0_05]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) ~[na:1.7.0_05]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157) ~[na:1.7.0_05]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) ~[na:1.7.0_05]
at java.net.Socket.connect(Socket.java:579) ~[na:1.7.0_05]
at org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:501) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:464) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:55) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.transport.AbstractInactivityMonitor.start(AbstractInactivityMonitor.java:138) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58) ~[activemq-client-5.9.1.jar:5.9.1]
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:338) ~[activemq-client-5.9.1.jar:5.9.1]
... 53 common frames omitted
我的ActiveMq正在运行,我可以访问http://localhost:8161/admin/queues.jsp我不知道为什么我会收到拒绝访问错误。
答案 0 :(得分:8)
在浪费了一整天这个错误后,我可以通过更改activemq url来解决它:
来自
activemq_location=tcp://localhost:61616
到
activemq_location=tcp://0.0.0.0:61616