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

915 views Asked by At

What settings shall be configured in order to be able to send JMS messages to a given topic in Wildfly 17 and receive them via JMS?

After looking in internet I found the following sources:

Remote JMS Client for Wildfly 8

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

Integrate ActiveMQ with Wildfly

However, none of the above mentioned links solved my problem completely

1

There are 1 answers

0
Alex Mi On

1.) A special Application user shall be created in Wildfly 17 using the command

add-user.sh/add-user.cmd

which belongs to the group "guests", and on behalf of whom the JMS Message Producer will create JMS messages. Details about how this user shall be created are given here:

use add-user.sh/add-user.cmd to create a new user in Wildfly

2.) Wilffly 17 must be started using

standalone-full.xml

not just

   standalone.xml

3.) Message Topic shall be created in Wildfly17, where the messages shall be sent to. This shall be possible either by running the script jboss-cli.bat / jboss-cli.bat with the following arguments:

jms-topic add --topic-address=AuctionTopic --entries=[#topic/auction", "java:jboss/exported/jms/topic/auction"]

or by directly inserting the following entry at line 537 of standalone-full.xml:

<jms-topic name="topic/testTopic" entries="java:/jms/topic/auction java:jboss/exported/jms/topic/auction" />

just before the existing line:

  <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>

4.) When a message producer that is a component residing inside Wildfly 17 (such as a servlet) does obtain a JMS Connection from WildFly 17, the following code shall be used:

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;

where

Constants.JMS_CONNECTION_FACTORY = "ConnectionFactory";

and

Constants.JMS_TOPIC_NAME = "java:/jms/topic/auction";