java - Apache Camel JMS : "Not allowed to create destination" when trying to connect to a queue

标签 java spring jms apache-camel tibco

我正在尝试在 Camel 中设置一条从 JMS 队列读取消息的路由。

应用程序使用Tibco,我不允许在此处发布任何数据,但工厂和队列的路径遵循格式/path/to/queueName:type,其中type可以是qcf(队列连接工厂) )和队列。

我使用的是 Spring-DSL,XML 是:

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">...</prop>
            <prop key="java.naming.provider.url">...LDAP Server URL...</prop>
            <prop key="java.naming.referral">follow</prop>
            <prop key="java.naming.security.credentials">...</prop>
            <prop key="java.naming.security.principal">uid=...,ou=...,dc=...,dc=...</prop>
        </props>
    </property>
</bean>

<bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate"/>
    <property name="jndiName" value="/path/to/queueConnectionFactory:qcf"/>
</bean>

<bean id="authenticatedConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="jmsQueueConnectionFactory"/>
    <property name="username" value="..."/>
    <property name="password" value="..."/>
</bean>

<bean id="testjms" class="org.apache.camel.component.jms.JmsComponent"> 
    <property name="connectionFactory" ref="authenticatedConnectionFactory"/> 
</bean>

<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
    <route id="jmsRouteTest">
        <from uri="testjms:queue:/path/to/queue:queue" />
        <to uri="file:c:\inbox?fileName=jmsMessage.txt" />
    </route>
</camelContext>

当应用程序运行时,它会不断在日志中抛出以下几行:

12:41:19:385 - WARN - DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'path/to/queue:queue' - trying to recover. Cause: Not allowed to create destination
12:41:20:494 - INFO - DefaultMessageListenerContainer - Successfully refreshed JMS Connection

需要注意的一件事是,目标的第一个斜杠“/”消失了,但如果我从 URI 中删除“queue:”,则会发生相同的错误,但目标变为“/path/to/queue:queue” '.

我已经搜索了这个错误并在 stackoverflow 上找到了一个问题: Does anyone know exactly what javax.jms.InvalidDestinationException: Not allowed to create destination means?

为了确保配置正确,我创建了以下类(将完全相同的设置从 Spring XML 复制到该类):

import java.util.Properties;

import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import java.io.*;

public class Test {

public static void main(String[] args) throws Exception {
    Properties properties = new Properties();

    properties.put("java.naming.provider.url", "...LDAP Server URL...");
    properties.put("java.naming.factory.initial", "...");
    properties.put("java.naming.referral", "follow");
    properties.put("java.naming.security.principal", "uid=...,ou=...,dc=...,dc=...");
    properties.put("java.naming.security.credentials", "...");
    properties.put("JmsConnectionFactory", "/path/to/queueConnectionFactory:qcf");
    properties.put("JmsDestinationName", "/path/to/queue:queue");
    properties.put("JmsUserName", "...");
    properties.put("JmsPassword", "...");

    Context context = null;
    QueueConnection connection = null;
    QueueSession session = null;
    QueueReceiver receiver = null;

    context = new InitialContext(properties);

    Queue queue = (Queue) context.lookup((String) properties.get("JmsDestinationName"));
    QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) context.lookup((String) properties.get("JmsConnectionFactory"));

    connection = queueConnectionFactory.createQueueConnection((String) properties.getProperty("JmsUserName"), 
                                                              properties.getProperty("JmsPassword"));

    session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    connection.start();

    receiver = session.createReceiver(queue);

    while (true) {
        TextMessage message = (TextMessage) receiver.receive();

        System.out.println("Received: " + message.getText());

        BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
        String s = bufferRead.readLine();

        if ("b".equals(s)) {
            break;
        }
    }

    connection.close();
}

}

通过这个类,我可以读取队列中的消息。

以前有人遇到过这个问题吗?

如果你们需要更多信息,请告诉我。

谢谢。

最佳答案

听起来您需要一些 Tibco 管理员才能首先在 Tibco 消息代理上创建该队列。

关于java - Apache Camel JMS : "Not allowed to create destination" when trying to connect to a queue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22100830/

相关文章:

java - 旧的垃圾收集已满且无法清理,可能是因为索引

java - 如何在 Spring Java Config 的单个 MessageListenerContainer 中添加多个 JMS MessageListners

java - Eclipse 在启动时挂起

java - 资源未释放

spring - 运行 spring 应用程序时出现 java.lang.NoClassDefFoundError

java - Spring Boot 使用或不使用 Maven 运行?如果没有,JSP 就无法解析

java - 在枚举字段 (DB​​) 中插入字符串值 (java) 时获取 "Data truncated for column"

java - SpecJMS 和 HornetQ

java - 什么是原始类型,为什么我们不应该使用它呢?

javascript - Selenium ,java,js "Exception in thread "主“org.openqa.selenium.JavascriptException : missing ) after argument list"