1.) 应使用命令在 Wildfly 17 中创建一个特殊的应用程序用户
add-user.sh/add-user.cmd
它属于“guests”组,JMS 消息生产者将代表他们创建 JMS 消息。此处提供了有关如何创建此用户的详细信息:
use add-user.sh/add-user.cmd to create a new user in Wildfly
2.) 必须使用 Wilffly 17 启动
standalone-full.xml
不只是
standalone.xml
3.) 消息主题应在 Wildfly17 中创建,消息应发送到该处。这可以通过运行带有以下参数的脚本jboss-cli.bat / jboss-cli.bat 来实现:
jms-topic add --topic-address=AuctionTopic --entries=[#topic/auction", "java:jboss/exported/jms/topic/auction"]
或者直接在standalone-full.xml的第537行插入以下条目:
<jms-topic name="topic/testTopic" entries="java:/jms/topic/auction java:jboss/exported/jms/topic/auction" />
就在现有行之前:
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
4.) 当作为位于 Wildfly 17 内部的组件(例如 servlet)的消息生产者确实从 WildFly 17 获得 JMS 连接时,应使用以下代码:
Properties props = new Properties();
// Wildfly 17.00:
// this user and password shall be created before the application is deployed
// with the help of add-user.sh. The jmsuser shall be an application user that // belongs to the group guest
props.put(Context.SECURITY_PRINCIPAL, "jmsuser");
props.put(Context.SECURITY_CREDENTIALS, "Password1!");
javax.naming.InitialContext ctx = new InitialContext(props);
Object obj = ctx.lookup(Constants.JMS_CONNECTION_FACTORY);
ConnectionFactory factory = (ConnectionFactory) obj;
this.jmsConnection = factory.createConnection();
obj = ctx.lookup(Constants.JMS_TOPIC_NAME);
this.topic = (Topic) obj;
在哪里
Constants.JMS_CONNECTION_FACTORY = "ConnectionFactory";
和
Constants.JMS_TOPIC_NAME = "java:/jms/topic/auction";