java - 无法连接到 Wildfly 上的远程 MDB - 找不到名称
问题描述
我在连接到 Wildfly 远程队列时遇到问题。
我在 Wildfly 实例上的 MDB 是:
@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "queue/HELLOWORLDMDBQueue"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")})
public class HelloWorldQueueMDB implements MessageListener {
private static final Logger LOGGER = Logger.getLogger(HelloWorldQueueMDB.class.toString());
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message rcvMessage) {
TextMessage msg = null;
try {
if (rcvMessage instanceof TextMessage) {
msg = (TextMessage) rcvMessage;
LOGGER.info("Received Message from queue: " + msg.getText());
} else {
LOGGER.warning("Message of wrong type: " + rcvMessage.getClass().getName());
}
} catch (JMSException e) {
throw new RuntimeException(e);
}
}
}
独立客户端是:
public class HelloWorldJMSClient {
private static final Logger log = Logger.getLogger(HelloWorldJMSClient.class.getName());
// Set up all the default values
private static final String DEFAULT_MESSAGE = "Hello, World!";
private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
private static final String DEFAULT_DESTINATION = "queue/HELLOWORLDMDBQueue";
private static final String DEFAULT_MESSAGE_COUNT = "1";
private static final String DEFAULT_USERNAME = "quickstartUser";
private static final String DEFAULT_PASSWORD = "quickstartPwd1!";
private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory";
private static final String PROVIDER_URL = "http-remoting://127.0.0.1:8080";
public static void main(String[] args) {
Context namingContext = null;
try {
String userName = System.getProperty("username", DEFAULT_USERNAME);
String password = System.getProperty("password", DEFAULT_PASSWORD);
// Set up the namingContext 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, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
namingContext = 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 = (ConnectionFactory) namingContext.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 = (Destination) namingContext.lookup(destinationString);
log.info("Found destination \"" + destinationString + "\" in JNDI");
int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));
String content = System.getProperty("message.content", DEFAULT_MESSAGE);
try (JMSContext context = connectionFactory.createContext(userName, password)) {
log.info("Sending " + count + " messages with content: " + content);
// Send the specified number of messages
for (int i = 0; i < count; i++) {
context.createProducer().send(destination, content);
}
// Create the JMS consumer
JMSConsumer consumer = context.createConsumer(destination);
// Then receive the same number of messages that were sent
for (int i = 0; i < count; i++) {
String text = consumer.receiveBody(String.class, 5000);
log.info("Received message with content " + text);
}
}
} catch (NamingException e) {
log.severe(e.getMessage());
} finally {
if (namingContext != null) {
try {
namingContext.close();
} catch (NamingException e) {
log.severe(e.getMessage());
}
}
}
}
}
错误输出是:
pro 10, 2020 1:49:20 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Found connection factory "jms/RemoteConnectionFactory" in JNDI
pro 10, 2020 1:49:20 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
INFO: Attempting to acquire destination "queue/HELLOWORLDMDBQueue"
pro 10, 2020 1:49:20 PM org.jboss.as.quickstarts.jms.HelloWorldJMSClient main
SEVERE: queue -- service jboss.naming.context.java.jboss.exported.queue
我正在使用wildfly 21,但我不知道自己做错了什么。
在 wildfly 管理控制台中,我可以看到 MDB:
URI
java:/queue/HELLOWORLDMDBQueue
Class Name
org.apache.activemq.artemis.jms.client.ActiveMQQueue
Value
ActiveMQQueue[jms.queue.HelloWorldMDBQueue]
更新:
执行:
jms-queue add --queue-address=HelloWorldQueueMDB --entries=queue/HelloWorldQueueMDB,java:jboss/exported/jms/queue/HelloWorldQueueMDB
在野蝇方面,我得到了:
15:05:27,427 ERROR [org.apache.activemq.artemis.core.client] (default I/O-53) AMQ214013: Failed to decode packet: java.lang.NoClassDefFoundError: java/security/acl/Group
更新:
java/security/acl/Group 已从 java14 中删除,因此可以使用旧版本的 java。
解决方案
因此,您正在尝试远程访问队列而不是 MDB。您的队列应该使用 jboss/exported 命名空间对外公开。java:jboss/exported/queue/HELLOWORLDMDBQueue 可以工作并使队列可用。您可以查看 WildFly HelloworlJms 快速入门或 HelloworldMdb 以获取此类示例
推荐阅读
- node.js - 将nodejs连接到rabbitmq时出错
- reactjs - 列出最终 webpack 包中包含的所有第三方库
- asp.net-core - 尝试在.net Core 5 Razor pages 项目中生成可点击的电话链接
- python-3.x - 如何使用“评估”关键字比较机器人框架中的两个字符串
- javascript - 在 json 文件中搜索仅包含 javascript 和 fs 的值
- java - 使用 Apache Commons Compressor 进行慢速 LZ4 解压
- php - Woocommerce如何使类别可链接
- haskell - QuickCheck 生成器未终止
- vue.js - 如何使用将 Vue 2 $on、$emit 事件总线迁移到 Vue3?
- mysql - 获取最大连续零个数 SQL