I am trying to setup a route in Camel that reads messages from a JMS queue.
The application uses Tibco and I am not allowed to post here any of the data, but the path for the factory and the queue follows the format /path/to/queueName:type, where type can be qcf (Queue Connection Factory) and queue.
I am using the Spring-DSL, the XML is:
<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>
While the application is running it keeps throwing the following lines in the log:
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
One thing to notice is that the first slash "/" for the destination disappears, but if I remove the "queue:" from the URI the same error occurs, but the destination becomes '/path/to/queue:queue'.
I have searched for this error and find a question here on stackoverflow:
Does anyone know exactly what javax.jms.InvalidDestinationException: Not allowed to create destination means?
Just to be sure that the configuration is correct, I have created the following class (copying the exact same settings from Spring XML to the class):
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();
}
}
With this class I am able to read the messages that are in the queue.
Have anyone experienced this problem before?
Please let me know if you guys need more information.
Thank you.