Tuesday, September 29, 2009

EMS: Steps to Send/Receive Message

EMS:  Steps to Send/Receive Message

 

Here are the steps to send/receive message from client side, (java code)

 

  1. Create a connection factory.

 

ConnectonFactory f = new com.tibco.tibjms.TibjmsConnectionFactory(String serverURL);

 

  1. Create a connection

Connection c = f.createConnection(String username, String password);

      If the server property authorization is disabled, you do not need to specify the username and password.

 

  1. Create a session

Session s=c.createSession(Boolean transcationFlag, Int delivery_mode);

 

  1. Get destination

Javax.jms.Queue d=s.CreateQueue(String queueName);

Javax.jms.Topic d=s.CreateTopic(String topicName);

 

Once the Queue/Topic exists, then return the destination object.

 

 

  1. Create message producer to send message, or

MessageProducer p=s.createProducer(Destination  d);

 

Create a Message object, TextMessage object for example,

TextMessage tm = s.createTextMessage();

You can set property for the message and the text body.

tm.setText(String textBody);

tm.setStringProperty(String propertyName, String propertyValue);

p.send(tm);

 

 

  1. Create message consumer to receive message

 MessageConsumer p=s.createConsumer(Destination d, String selector);

     

      For synchronously receiver,

      p.receive();

 

     For asynchronously receiver, you need to implement MessageListener class and restruture the onMessage function.

Class myMessageListener implements MessageListener

{

Public void onMessage(Message message)

{

// add code here to handle if message is sent to queue/topic

   System.out.println(“The imcoming message is: “+message);

}

}

 

     In the main class, set consumer listener

p.setMessageListener(new myMessageListener);

 

Note that, for the MessageConsumer class, you need to start the connection before receive message from Queue/Topic

  1. start();

 

Note: another way to get the ConnectionFactory/Queue/Topic object JNDI interface.

 

 

 

1 comment:

Anonymous said...

Hi, I'm a newbie here, but I already want to bring all the benefits of me :) So, I want to share my experience with you..
9 days ago, accidentally, i had found the Mobile Phone TV...and I was so delighted with this application
that I decided to talk to you :)

I consider myself a bit of a road warrior. I am on and off jets and through airports at least twice,
usually 4 times a week. I can catch up on news, watch a Discovery program, check up on the stock market or just find something interesting.
The live guide works like cable at home and the connection speed is very good. All in ALL - I RATE A 5 Star program!

but I do not want to leave any links here, so you can email me fairyalexiss@gmail.com
and i will give you the site of this unusual program :)

(but please don't PM me, because it's so difficult to communicate in such kind of way)

so, I hope I was helpful to you)) see you in next posts ..

sincerely
your Alexis....

p.s. English is not my native language, so sorry for any mistakes :)