【问题标题】:Enable sending to / receiving from a JMS topic in Wildfly 17在 Wildfly 17 中启用向 JMS 主题发送/接收
【发布时间】:2020-12-04 14:19:07
【问题描述】:

为了能够向 Wildfly 17 中的给定主题发送 JMS 消息并通过 JMS 接收它们,应配置哪些设置?

在网上查了一下,我找到了以下来源:

Remote JMS Client for Wildfly 8

Not able to send message to a Topic configured on WildFly 9

Integrate ActiveMQ with Wildfly

但是,上述链接都没有完全解决我的问题

【问题讨论】:

    标签: java jboss jms-topic wildfly-17


    【解决方案1】:

    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";
    

    【讨论】:

      猜你喜欢
      • 2018-10-21
      • 2016-02-03
      • 1970-01-01
      • 2016-10-05
      • 1970-01-01
      • 2016-09-02
      • 2018-07-30
      • 1970-01-01
      • 2011-12-12
      相关资源
      最近更新 更多