Skip to content

Instantly share code, notes, and snippets.

@mmacphail
Created July 26, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmacphail/80e7d3ad4158b87fba1c34f72da4e9d7 to your computer and use it in GitHub Desktop.
Save mmacphail/80e7d3ad4158b87fba1c34f72da4e9d7 to your computer and use it in GitHub Desktop.
Connect to Universal Messaging using JMS
import java.util.Hashtable;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class HelloUMJNDI {
public static void main(String[] args) throws NamingException, JMSException {
Hashtable<String, String> env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.pcbsys.nirvana.nSpace.NirvanaContextFactory");
env.put(Context.PROVIDER_URL, "nsp://local-dev:9000");
Context ctx = new InitialContext(env);
ConnectionFactory connFactory = (ConnectionFactory) ctx.lookup("local_um");
Connection conn = connFactory.createConnection();
Topic topic = (Topic) ctx.lookup("externalClientTopic");
Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
Message message = session.createTextMessage("Hello World !");
producer.send(message);
conn.close();
ctx.close();
}
}
@mmacphail
Copy link
Author

Jars needed :

  • nClient.jar
  • nJMS.jar
  • jboss-jms-api_1.1_spec-1.0.1.Final.jar

@OussaamaElBergui
Copy link

Bonjour,
Svp , est ce qu'il y a une possibilité de lister tous les queues, dans une liste . Merci de m'aider.

@yogeshdhavan
Copy link

yogeshdhavan commented Dec 5, 2019

Connection conn = connFactory.createConnection();
asking fro typeCasting
@mmacphail

@mmacphail
Copy link
Author

@OussamaElBergui to list all jars and topics I think you need to use directly the UM API and not the JMS API.

@mmacphail
Copy link
Author

@yogeshdhavan
Can you clarify your question?

@younisshah
Copy link

Jars needed :

  • nClient.jar
  • nJMS.jar
  • jboss-jms-api_1.1_spec-1.0.1.Final.jar

I am new to UM - like just started. Where do we get these jars from? Is there any artifact repository for these jars?

@mmacphail
Copy link
Author

@younisshah
These jar are not available in any artifact repository by default you need to add them from your org (except from the jms api).
You can find the nClient.jar and nJMS.jar in the UM install lib directory.

@younisshah
Copy link

younisshah commented May 28, 2020

@younisshah
These jar are not available in any artifact repository by default you need to add them from your org (except from the jms api).
You can find the nClient.jar and nJMS.jar in the UM install lib directory.

Thank you. How does one use ActiveMQ with UM? Do you have a gist for that?

@mmacphail
Copy link
Author

@younisshah I'm not sure what you mean :).
What are you trying to do ?

@wuriyanto48
Copy link

@mmacphail, i am getting an error [Root exception is com.pcbsys.nirvana.client.nSessionNotConnectedException: The session is not currently connected to the server. Unable to perform the request:Session has been closed via another thread].

@mmacphail
Copy link
Author

mmacphail commented Oct 12, 2020

Both threads use the same session, but it seems one thread closed the session. You want to open the session in each independent thread, or do not close the session at all in the threads and close it when the app finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment