4 Replies Latest reply on Jun 26, 2019 5:15 AM by mayerw01

    Create queue dynamically after Wildfly server is started

    wwang2016

      Hi,

       

      I am on Wildfly 15.

       

      I need to create dynamic queues ( queue names based on data from a query) during/after server starts up. In Java, you can have a CDI bean with a method annotated with @PostConstruct

       

      I was trying to use Artemis api to create dynamic queues and I have not had luck so far.

       

      Java code:

       

              ActiveMQConnectionFactory activeMqconnectionFactory = new ActiveMQConnectionFactory();

              Connection connection = activeMqconnectionFactory.createConnection();

              connection.start();

              Session session = connection.createSession( false, Session.AUTO_ACKNOWLEDGE );

               session.createQueue(SOME_DYNAMIC_NAME)

       

      I have custom configuration in standalone-full.xml

       

      Under:

      <subsystem xmlns="urn:jboss:domain:messaging-activemq:5.0">

      <server>

       

      <remote-connector name="netty" socket-binding="activemq-5x">

                          <param name="use-nio" value="true"/>

                          <param name="use-nio-global-worker-pool" value="true"/>

                      </remote-connector>

      <remote-acceptor name="activemq-5x-acceptor" socket-binding="activemq-5x"/> 

       

      under: <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">

       

      <socket-binding name="activemq-5x" interface="public" port="61616"/>

       

      I got the following error:

       

          Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance

          Caused by: javax.jms.JMSException: Failed to create session factory

          Caused by: ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]"}}

       

      What is missing in the investigation?

       

      Thanks,

       

      Wayne

        • 1. Re: Create queue dynamically after Wildfly server is started
          wwang2016

          I also tried

           

          ActiveMQConnectionFactory activeMqconnectionFactory = new ActiveMQConnectionFactory( "vm://localhost" );

           

          I got the same error message

          • 2. Re: Create queue dynamically after Wildfly server is started
            wwang2016

            I removed port-offset (it was 400), and now I got a different error message:

             

                Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance

                Caused by: javax.jms.JMSSecurityException: AMQ119031: Unable to validate user from /127.0.0.1:56008. Username: null; SSL certificate subject DN: unavailable

                Caused by: ActiveMQSecurityException[errorType=SECURITY_EXCEPTION message=AMQ119031: Unable to validate user from /127.0.0.1:56008. Username: null; SSL certificate subject DN: unavailable]"}}

             

            It looks like I need some additional configuration?

            • 3. Re: Create queue dynamically after Wildfly server is started
              jewellgm

              Rather than directly instantiating the connection factory, have you tried resource injection?  The resource will be available to you during the execution of the method marked with @PostConstruct.

               

              @Resource

              ConnectionFactory cf;

               

              You can specify the JNDI name of the connection factory inside the annotation if the default CF isn't the one you want.

               

              Is your bean marked as a @Singleton, or are you taking some other precaution to make sure the dynamic queue hasn't already been created?

              • 4. Re: Create queue dynamically after Wildfly server is started
                mayerw01

                Did you try this?

                ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://${hostname}:61616");