5

我已经配置了一个在 JBoss AS 7.1.1.FINAL 上运行的 JMS 队列,standalone-full.xml用作配置文件。

然后,我基于 JBoss 示例代码编写了一个独立的 Java 程序来连接到队列并发送消息。

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();
        }
    }
}

不幸的是,调用connectionFactory.createConnection失败并出现 JMS 异常 ( HornetQException[errorCode=3 message=Timed out waiting to receive cluster topology. Group:null):

日志:

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

问:不涉及集群,两个程序在同一台机器上运行,我没有配置任何IP地址。有谁知道我在 JBoss 配置中可能缺少什么?

欢迎任何提示:-)

4

2 回答 2

6

我通过检查和更改项目的 Maven 依赖项解决了这个问题。

有了这个 Maven 依赖项,程序按预期工作:

<dependency>
    <groupId>org.jboss.as</groupId>
    <artifactId>jboss-as-jms-client-bom</artifactId>
    <version>7.1.1.Final</version>
    <type>pom</type>
</dependency>
于 2012-11-07T15:31:47.013 回答
0

我有同样的问题,但产品版本不同。具体来说,我试图让 Spring Boot(版本 1.4.1)应用程序向 HornetQ Server 版本 2.3.25.SP13(嵌入在 JBoss EAP 6.4.10 服务器上)发送消息。解决方案是将以下依赖项添加到我的 Spring Boot 应用程序中:

    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms-client</artifactId>
        <version>2.3.22.Final</version>
    </dependency>
于 2017-10-19T12:48:37.737 回答