3 Replies Latest reply on Oct 26, 2018 1:53 AM by Miroslav Novak

    Wildfly 10 send jms message from local wildfly instance to remote wildfly instance

    Kevin Stone Newbie

      Here is a snippet of code.  Works just fine, EXCEPT the message is sent to the local queue not the remote queue.  Anyone?

       

      Connection conn = null;
      Session sess = null;
      MessageProducer prod = null;
      String queueHost ="IP OF REMOTE HOST";
      String remoteUserName="test";
      String remoteUserPassword="test";
      int delaySecs = 0;
      String queueName="TestQueue";
      
      // Get the IP for the queue host
      String hostAddress = InetAddress.getByName(queueHost).getHostAddress();
      log.info("Host address " + hostAddress);
      
      // Load properties
      final Properties env = new Properties();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
      env.put(Context.PROVIDER_URL, "http-remoting://" + hostAddress + ":8080");
      env.put(Context.SECURITY_PRINCIPAL, remoteUserName);
      env.put(Context.SECURITY_CREDENTIALS, remotePassword);
      InitialContext ic = new InitialContext(env);
       
      // Look up the factory and create a connection
      String jmsFactory = "java:jboss/exported/jms/RemoteConnectionFactory";
      QueueConnectionFactory qconFactory = (QueueConnectionFactory) ic.lookup(jmsFactory);
      conn = qconFactory.createConnection(remoteUserName, remotePassword);
       
      //Create the session
      boolean transacted = false;
      sess = conn.createSession(transacted, QueueSession.AUTO_ACKNOWLEDGE);
      queue = sess.createQueue(queueName);
      if (queue == null) {
          throw new NamingException("Queue:" + queueName + " NOT FOUND!");
      }
       
      // get a message producer/sender and start the connection
      prod = sess.createProducer(queue);
      conn.start();
       
      TextMessage tmsg = sess.createTextMessage();
      // set the message into the Text
      tmsg.setText(msg);
      tmsg.setJMSReplyTo(sess.createQueue(queueName));
       
      if (delaySecs > 0) {
          // set message delay
          tmsg.setLongProperty("_AMQ_SCHED_DELIVERY", delaySecs * 1000);
      }
       
      // send it
      prod.send(tmsg);