Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create JMS connection from standalone Java application to JBoss AS 7 message queue

Tags:

jms

jboss7.x

I have configured a JMS queue running on JBoss AS 7.1.1.FINAL, using standalone-full.xml as configuration profile.

I then wrote a standalone Java program to connect to the queue and send a message, based on the JBoss sample code.

public class RemoteProducer {

    private static final Logger log = Logger.getLogger(RemoteProducer.class.getName());

    // Set up all the default values
    private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
    private static final String DEFAULT_DESTINATION = "jms/queue/test";
    private static final String DEFAULT_USERNAME = "jmstest";
    private static final String DEFAULT_PASSWORD = "fluppy";
    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
    private static final String PROVIDER_URL = "remote://localhost:4447";

    /**
     * @param args
     */
    public static void main(String[] args) {
        ConnectionFactory connectionFactory = null;
        Connection connection = null;
        Session session = null;
        MessageProducer producer = null;
        Destination destination = null;
        Context context = null;

        try {
            // Set up the context for the JNDI lookup
            final Properties env = new Properties();
            env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
            env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
            env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));
            env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));
            context = new InitialContext(env);

            // Perform the JNDI lookups
            String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
            log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
            connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString);
            log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");

            String destinationString = System.getProperty("destination", DEFAULT_DESTINATION);
            log.info("Attempting to acquire destination \"" + destinationString + "\"");
            destination = (Destination) context.lookup(destinationString);
            log.info("Found destination \"" + destinationString + "\" in JNDI");

            // Create the JMS connection, session, producer, and consumer
            connection = connectionFactory.createConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            producer = session.createProducer(destination);
            connection.start();

            // TODO send messages

        } catch (NamingException e) {
            e.printStackTrace();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

Unfortunately, the call to connectionFactory.createConnection fails with a JMS exception (HornetQException[errorCode=3 message=Timed out waiting to receive cluster topology. Group:null):

Log:

Nov 06, 2012 3:37:42 PM de.test.jms.RemoteProducer main
INFO: Attempting to acquire connection factory "jms/RemoteConnectionFactory"
Nov 06, 2012 3:37:42 PM de.test.jms.RemoteProducer main
INFO: Found connection factory "jms/RemoteConnectionFactory" in JNDI
Nov 06, 2012 3:37:42 PM de.test.jms.RemoteProducer main
INFO: Attempting to acquire destination "jms/queue/test"
Nov 06, 2012 3:37:42 PM de.test.jms.RemoteProducer main
INFO: Found destination "jms/queue/test" in JNDI
javax.jms.JMSException: Failed to create session factory
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:605)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:119)
    at de.test.jms.RemoteProducer.main(RemoteProducer.java:60)
Caused by: HornetQException[errorCode=3 message=Timed out waiting to receive cluster topology. Group:null]
    at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:804)
    at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:601)
    ... 2 more

Question: There is no cluster involved, both programs run on the same machine, I did not configure any IP addresses whatsoever. Does anyone have an idea what I may be missing in the JBoss configuration?

Any hints welcome :-)

like image 411
skowski Avatar asked Nov 06 '12 14:11

skowski


1 Answers

I solved the problem with checking and changing the Maven dependencies of my project.

With this Maven dependency the program worked as expected:

<dependency>
    <groupId>org.jboss.as</groupId>
    <artifactId>jboss-as-jms-client-bom</artifactId>
    <version>7.1.1.Final</version>
    <type>pom</type>
</dependency>
like image 162
skowski Avatar answered Sep 30 '22 05:09

skowski