aspose file tools*
The moose likes JBoss/WildFly and the fly likes Need Help With JBoss/JMS/JNDI/MQSeries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Need Help With JBoss/JMS/JNDI/MQSeries" Watch "Need Help With JBoss/JMS/JNDI/MQSeries" New topic
Author

Need Help With JBoss/JMS/JNDI/MQSeries

Pyper John
Greenhorn

Joined: Aug 13, 2001
Posts: 3
I have been recently assigned at work to figure out how to use JBoss to connect to MQSeries through JNDI. My problem (and frustration) is that I know none of these technologies. I have used Tomcat before, but never used nor worked with JNDI or any messaging service. I am quit lost where to too begin and don�t have the luxury of taking time to figure out as much as I would like.

Where would I begin?

For now, I am just trying to use JMS and JBoss through Eclipse. Is there a simple example application with instructions on how to do this? What JBoss files need to be edited? What libraries are needed? What does the code look like? I�m still confused as to what JMS and JNDI are and how they relate. Once I figure that out, I will worry about MQSeries.

Thanks in advance�
Ambily G Nair
Greenhorn

Joined: Aug 21, 2004
Posts: 28
Hi,

Have a look on this tutorial.

http://www.huihoo.com/jboss/online_manual/3.0/ch08s07.html

I think this will help you to get an idea about jbossmq and jms

-- Ambily
Pyper John
Greenhorn

Joined: Aug 13, 2001
Posts: 3
Ok, I think I got it figured out� let me know if this is right. I just need to configure the JBoss JNDI with the MQSeries server/queue information. Then call the JNDI api to populate the JMS api with the right values to send and receive messages from MQSeries. Is this right? Does someone have an example of how to configure the JNDI properties file and use it to send/retrieve a message from MQSeries?
Ambily G Nair
Greenhorn

Joined: Aug 21, 2004
Posts: 28
Hi,

I have tried jbossmq/jms with the following code and I was able to send and receive messages.

Sender code is

public class QueueSender1 {
private static InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();

props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");

// This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password");

InitialContext initialContext = new InitialContext(props);
return initialContext;
}

public static void main(String[] args) throws Exception {
InitialContext ctx = getContext();
QueueConnectionFactory cf = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
QueueConnection c = cf.createQueueConnection();
QueueSession s = c.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue q = (Queue) ctx.lookup("queue/textQueue");
QueueSender snd = s.createSender(q);
TextMessage msg = s.createTextMessage();
msg.setText("Hello JMS World!");
snd.send(msg);
snd.close();
s.close();
c.close();
}

}


Receiver code is ,

public class QueueReceiver1 implements MessageListener{
public void onMessage(Message msg) {
try {
String msgText = ((TextMessage) msg).getText();
System.out.println("Message Received: "+ msgText );
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
InitialContext ctx = getContext();
QueueConnectionFactory cf = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
QueueConnection c = cf.createQueueConnection();
QueueSession s = c.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue q = (Queue) ctx.lookup("queue/textQueue");
QueueReceiver rcv = s.createReceiver(q);
rcv.setMessageListener(new QueueReceiver1());
c.start();
while (true);
}
private static InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();

props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");

// This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password");

InitialContext initialContext = new InitialContext(props);
return initialContext;
}

}


Also you have to edit login-config.xml,jbossmq-destinations-service.xml.
Mario Rodriguez
Greenhorn

Joined: Sep 08, 2005
Posts: 1
Any of you guys, could configure JBoss + JNDI + MQSeries ?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Need Help With JBoss/JMS/JNDI/MQSeries