Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help With JBoss/JMS/JNDI/MQSeries

 
Pyper John
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any of you guys, could configure JBoss + JNDI + MQSeries ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic