骆驼路由输入端点的 JBoss 嵌入式 MQ 的 jndi 查找问题

Posted

技术标签:

【中文标题】骆驼路由输入端点的 JBoss 嵌入式 MQ 的 jndi 查找问题【英文标题】:Having issues with jndi lookup for JBoss embedded MQ for camel route input endpoint 【发布时间】:2016-07-11 09:43:40 【问题描述】:

我正在尝试从 JBoss 上的嵌入式 MQ 检索消息。我暂时关闭了安全性。队列的 jndi 名称看起来像 xQueue [java:/jms/queue/xQueue]

我正在尝试从运行在 tomcat 上的 Spring Boot 应用程序访问它,并使用 Apache Camel 从该队列创建一个路由作为输入。

我的 JMS 配置

<bean name="jmsConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
        <constructor-arg name="ha" value="false"></constructor-arg>
        <constructor-arg>
            <bean name="transportConfiguration" class="org.hornetq.api.core.TransportConfiguration">
                <constructor-arg
                    value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
                <constructor-arg>
                    <map key-type="java.lang.String" value-type="java.lang.Object">
                        <entry key="host" value="127.0.0.1" />
                        <entry key="port" value="5445" />
                    </map>
                </constructor-arg>
            </bean>
        </constructor-arg>
    </bean>

<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
        <property name="destinationResolver" ref="destResolver" />
</bean>

<bean id="destResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate" />
</bean>

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate"
        lazy-init="true">
        <property name="environment">
            <props>
                <prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
                <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
            </props>
        </property>
    </bean>

我的路由器代码

import org.apache.camel.spring.boot.FatJarRouter;
import org.springframework.stereotype.Component;

@Component
public class RepConnectorRouter extends FatJarRouter 

    @Override
    public void configure() 
        from(
                "jms:queue:xQueue").autoStartup(true).to(
                "file://c:/temp/out");
    


我能够建立 jms 连接,但队列的 jndi 查找失败。我在路由器中尝试了各种与队列名称的组合。有没有人解决这个问题?

我的堆栈跟踪

2016-03-23 17:35:22.823  INFO 28172 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@23bb8443: startup date [Wed Mar 23 17:35:22 EDT 2016]; root of context hierarchy
2016-03-23 17:35:24.007  INFO 28172 --- [           main] o.s.b.f.xml.XmlBeanDefinitionReader      : Loading XML bean definitions from class path resource [common-jms.xml]
2016-03-23 17:35:24.660  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2016-03-23 17:35:24.665  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'camelContext': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=defaultConfig; factoryMethodName=camelContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ibcm/spider/DefaultConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.apache.camel.spring.boot.CamelAutoConfiguration; factoryMethodName=camelContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]]
2016-03-23 17:35:24.665  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'applicationController': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=defaultConfig; factoryMethodName=applicationController; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ibcm/spider/DefaultConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.apache.camel.spring.boot.CamelAutoConfiguration; factoryMethodName=applicationController; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]]
2016-03-23 17:35:24.666  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'producerTemplate': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=defaultConfig; factoryMethodName=producerTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ibcm/spider/DefaultConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.apache.camel.spring.boot.CamelAutoConfiguration; factoryMethodName=producerTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]]
2016-03-23 17:35:24.666  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'consumerTemplate': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=defaultConfig; factoryMethodName=consumerTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ibcm/spider/DefaultConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.apache.camel.spring.boot.CamelAutoConfiguration; factoryMethodName=consumerTemplate; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]]
2016-03-23 17:35:24.666  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'propertiesParser': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=defaultConfig; factoryMethodName=propertiesParser; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ibcm/spider/DefaultConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.apache.camel.spring.boot.CamelAutoConfiguration; factoryMethodName=propertiesParser; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]]
2016-03-23 17:35:24.666  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'properties': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=defaultConfig; factoryMethodName=properties; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ibcm/spider/DefaultConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.apache.camel.spring.boot.CamelAutoConfiguration; factoryMethodName=properties; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]]
2016-03-23 17:35:24.667  INFO 28172 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'camelBeanPostProcessor': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=defaultConfig; factoryMethodName=camelBeanPostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/ibcm/spider/DefaultConfig.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.apache.camel.spring.boot.CamelAutoConfiguration; factoryMethodName=camelBeanPostProcessor; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/apache/camel/spring/boot/CamelAutoConfiguration.class]]
2016-03-23 17:35:24.991  INFO 28172 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-03-23 17:35:25.190  INFO 28172 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.jms.annotation.JmsBootstrapConfiguration' of type [class org.springframework.jms.annotation.JmsBootstrapConfiguration$$EnhancerBySpringCGLIB$$2cd850e9] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-23 17:35:25.209  INFO 28172 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [class org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$16347185] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-03-23 17:35:26.042  INFO 28172 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8090 (http)
2016-03-23 17:35:26.266  INFO 28172 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-03-23 17:35:26.270  INFO 28172 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.20
2016-03-23 17:35:26.909  INFO 28172 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-03-23 17:35:26.910  INFO 28172 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4109 ms
2016-03-23 17:35:27.178  INFO 28172 --- [ost-startStop-1] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService  'metricsExecutor'
2016-03-23 17:35:28.060  INFO 28172 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2016-03-23 17:35:28.073  INFO 28172 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'metricFilter' to: [/*]
2016-03-23 17:35:28.074  INFO 28172 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-03-23 17:35:28.074  INFO 28172 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'webRequestLoggingFilter' to: [/*]
2016-03-23 17:35:28.074  INFO 28172 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-03-23 17:35:28.074  INFO 28172 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'applicationContextIdFilter' to: [/*]
2016-03-23 17:35:28.840  INFO 28172 --- [           main] o.a.c.i.converter.DefaultTypeConverter   : Loaded 183 type converters
2016-03-23 17:35:29.418  INFO 28172 --- [         main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-03-23 17:35:29.958  INFO 28172 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2016-03-23 17:35:30.036  INFO 28172 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
2016-03-23 17:35:30.219  INFO 28172 --- [           main] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.15.2 (CamelContext: camel-1) is starting
2016-03-23 17:35:30.220  INFO 28172 --- [           main] o.a.c.m.ManagedManagementStrategy        : JMX is enabled
2016-03-23 17:35:30.686  INFO 28172 --- [           main] o.a.camel.spring.SpringCamelContext      : AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance.
2016-03-23 17:35:30.686  INFO 28172 --- [           main] o.a.camel.spring.SpringCamelContext      : StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2016-03-23 17:35:31.758  INFO 28172 --- [           main] o.a.camel.spring.SpringCamelContext      : Route: route1 started and consuming from: Endpoint[jms://queue:jms/queue/xQueue]
2016-03-23 17:35:31.762  INFO 28172 --- [           main] o.a.camel.spring.SpringCamelContext      : Total 1 routes, of which 1 is started.
2016-03-23 17:35:31.763  INFO 28172 --- [           main] o.a.camel.spring.SpringCamelContext      : Apache Camel 2.15.2 (CamelContext: camel-1) started in 1.558 seconds
2016-03-23 17:35:31.913  INFO 28172 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8090 (http)
2016-03-23 17:35:31.915  INFO 28172 --- [           main] c.i.spider.PocApplication    : Started PocApplication in 9.635 seconds (JVM running for 17.429)
2016-03-23 17:35:42.701  WARN 28172 --- [connectorQueue]] c.c.j.DefaultJmsMessageListenerContainer : Setup of JMS message listener invoker failed for destination 'jms/queue/xQueue' - trying to recover. Cause: Destination [jms/queue/xQueue] not found in JNDI; nested exception is javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
2016-03-23 17:35:42.857  INFO 28172 --- [connectorQueue]] c.c.j.DefaultJmsMessageListenerContainer : Successfully refreshed JMS Connection

【问题讨论】:

在@Nicholas 上方添加 【参考方案1】:

问题是: 原因:在 JNDI 中找不到目的地 [jms/queue/xQueue];

我忘记了确切的正确前缀是什么,但它应该是这样的:

java:jms/queue/xQueue

【讨论】:

【参考方案2】:

如果您尝试从另一个 JVM(不是 JBoss)访问目标(在本例中为队列),您需要将队列和连接工厂都定义在 java:jboss/exported 名称空间中.

例如:

<entry name="java:jboss/exported/jms/queue/sample"/>

其他 JVM 通过 JNDI 查找可以使用此目标:

jms/queue/sample
道格

【讨论】:

以上是关于骆驼路由输入端点的 JBoss 嵌入式 MQ 的 jndi 查找问题的主要内容,如果未能解决你的问题,请参考以下文章

骆驼路线和端点

spring boot + mongodb + 骆驼路由连接问题

骆驼运行时计时器更改

来自 JBoss - RedHat codeready 的基于 Eclipse 的图形 Camel 编辑器是不是仅适用于 xml 中的骆驼?

apache骆驼轮询休息端点

骆驼发送到多个端点