Client for remote JMS queue

I have a JMS queue configured on a GlassFish remote server. I am trying to connect this queue from my local machine. Is it possible to connect directly to this server or do I need to connect through some broker / agent? How it works? (I'm fresh in the jms area) Thanks a lot

+6
source share
3 answers

If your client application runs outside of Glassfish, this is a simple example code for the mq open client.

To make it work, you will need to specify 2 openmq banks from the glassfishInstall / mq / lib directory - imq.jar and jms.jar

import com.sun.messaging.ConnectionConfiguration; import com.sun.messaging.ConnectionFactory; import com.sun.messaging.Queue; import javax.jms.Connection; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageProducer; import javax.jms.Session; public class TestJmsClientStandalone2 { public static void main( String[] args ) throws JMSException { ConnectionFactory connFactory = new ConnectionFactory(); connFactory.setProperty(ConnectionConfiguration.imqAddressList, "remotehostip:7676"); Queue myQueue = new Queue("myRemoteQueue"); try (Connection connection = connFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(myQueue)) { Message message = session.createTextMessage("this is my test message"); producer.send(message); } } } 
+10
source

Is your client application running on a local Glassfish instance and trying to connect to the remote glass fish JMS server resources?

If yes, then I found 2 ways to do this. For both options, the same connection between the factory and the target (queue) JMS Resources in remote and local instances in a glass form is configured.

1) Set jms parameter factory connection property "addressList"

In the admin console for Glassfish clients, click Resources->JMS Resources->Connection Factories->jms/YourConnectionFactory->Additional Properties

Add an additional property with the name addressList and value XX.XX.XX.XX: YYYY where value is the IP address of the remote machine and the port number on which the JMS service is running.

or

2) Install the Glassfish client Java Message Service application to connect to the remote glass shawl

In the admin console for Glassfish clients, click Configurations->server-config->Java Message Service

  • Set JMS service type: REMOTE (click "Save")
  • Set JMS Hosts->default_JMS_host IP address and port to be the IP address and port of the JMS service of the remote window.

I tested both options with Glassfish 4. Hope this helps.

+5
source

I have no experience with Glassfish, but this script works with JBoss (which integrates JBossMQ), and it should also be generally applicable:

Server:

  • Server configuration: create a queue and bind it to a name that should be visible in JNDI
  • Server configuration Make sure the factory connection is also visible in JNDI.

Customer:

  • Find the factory connection and queue using JNDI. This may require some values ​​to be entered in the properties for the InitialContext
  • In addition to connecting the factory and the queue, you can create other objects (connection / session / queue receiver).

As for JBoss, it looks like this:

  final Properties initialContextProperties = new Properties(); initialContextProperties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); initialContextProperties.put("java.naming.provider.url", "jnp://localhost:1099"); // final InitialContext ic = new InitialContext(initialContextProperties); final QueueConnectionFactory qcf = (QueueConnectionFactory) ic .lookup("XAConnectionFactory"); final Queue queue = (Queue) ic.lookup("queue/A"); 

So the broker / agent to go through is JNDI.

+3
source

Source: https://habr.com/ru/post/947993/


All Articles