• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Trying to write a jms client to receive as message

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write a JMS client and this is all the known info that I have...

JNDI Context URL: tibjmsnaming://199.82.204.23:7222
JNDI Context Factory: com.tibco.tibjms.naming.TibjmsInitialContextFactory
Queue Connection Factory : QueueConnectionFactory
QueueName : ESE.LAC.MSGS
JMS Property Names:
CARRIER_OID,TRACK_TYPE,ORIGIN_COUNTRY_CODE,DEST_COUNTRY_CODE

I tried to get it started, but really do nto know what to do:


import javax.naming.*;
import javax.jms.*;

public class JMS

{

String jndiContextUrl = "tibjmsnaming://199.82.204.23:7222";
String jndiContextFactory = "com.tibco.tibjms.naming.TibjmsInitialContextFactory";
String queueConnectionFactory = "QueueConnectionFactory";
String queueName = "ESE.LAC.MSGS";
private QueueConnectionFactory qFactory;
private QueueConnection qcon;
private QueueSession qsession;
private QueueSender qsender;
private Queue queue;
private TextMessage msg;


public JMS()

{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, jndiContextFactor);
env.put(Context.PROVIDER_URL, jndiContextUrl);

InitialContext jndiContext = new InitialContext(env);

qFactory = (QueueConnectionFactory) jndiContext.lookup(queueConnectionFactory);

queue = (Queue) jndiContext.lookup(queueName);

qreceiver = qsession.createReceiver(queue);
qreceiver.setMessageListener(this);

qcon.start();

}
}
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple of things I noticed:

You never created a qsession. So I would expect the line that has qreceiver = qsession.createReceiver(queue) would get an NPE. For just playing around a simple session is probably okay. Like:


By calling setMessageListener(this) you are saying that the JMS class is a message listener, but it does not implement the MessageListener interface. Do that and you will need to write an onMessage method that will be called when a message arrives.

Hopefully, that is enough info to get you going.
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic