gpt4 book ai didi

jms - 无法创建从独立 Java 应用程序到 JBoss AS 7 消息队列的 JMS 连接

转载 作者:行者123 更新时间:2023-12-04 14:23:58 26 4
gpt4 key购买 nike

我已经配置了一个在 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 配置中可能缺少什么?

欢迎任何提示:-)

最佳答案

我通过检查和更改项目的 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>

关于jms - 无法创建从独立 Java 应用程序到 JBoss AS 7 消息队列的 JMS 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13253609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com