簡體   English   中英

在 Wildfly 17 中啟用向 JMS 主題發送/接收

[英]Enable sending to / receiving from a JMS topic in Wildfly 17

為了能夠將 JMS 消息發送到 Wildfly 17 中的給定主題並通過 JMS 接收,應配置哪些設置?

在互聯網上查找后,我發現了以下來源:

Wildfly 8 的遠程 JMS 客戶端

無法向 WildFly 9 上配置的主題發送消息

將 ActiveMQ 與 Wildfly 集成

但是,上述鏈接都沒有完全解決我的問題

1.) 應使用以下命令在 Wildfly 17 中創建一個特殊的應用程序用戶

add-user.sh/add-user.cmd

它屬於“guests”組,JMS 消息生產者將代表他們創建 JMS 消息。 此處提供了有關如何創建此用戶的詳細信息:

使用 add-user.sh/add-user.cmd 在 Wildfly 中創建一個新用戶

2.) 必須開始使用 Wilffly 17

standalone-full.xml

不只是

   standalone.xml

3.) 消息主題應在 Wildfly17 中創建,消息應發送到的位置。 這可以通過使用以下 arguments 運行腳本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";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM