This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!

rahul batra

Greenhorn
+ Follow
since Nov 16, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by rahul batra

this is the worst forum i have ever been to , dumb people with no answers , huh
hello all ,
can anyone please tell me whats the best way to achieve request response format between two application.

i have one it this way, please correct me if i am wrong.

once i get a request , i create a message and i create a temporary queue for every request and send that temp queue destination along with my request to some appication who is listening , the listeneer then extracts my destination ans responds to that destination (temp queue) which i had created and to which i am listening.

but what i am worried about it that for every request i am creating a temp queue. so will it work in real time application where lets say 20-30 requests come at once, so my app will ccreate 20-30 temp queue. I am using Jboss 4.0.
and one more thing. are these temp queue destroyed automatically .if yes then i guess my approach should work i guess. i am pasting my code as well .
please do help me . thanks

Hello friends,
My application Requirement.
I have to send messages using QueueSender and all of those messages must be uniqely indentifiable on the queue since while responding to those messages i have to see to what message am i replying .
so i am haiving two problems

1) what to use and how to set a messages with some unique identifier before sending it using QueueSender on the queue.

2) while retreiving , i have to check the message for identifying it and then appropriately replying. so that means i will have to specify some message selector while creating my QueueReceiver using QueueSession. and then retreive only that message from queue which is equal to the value that i had set while sending the message

However i am not able to write the code for it though i went through the API's.

please do help if any one of you have done it earlier.
hi vishnu,thanks, that sounds interesting,
can u please tell me two things more
like does the Message Driven Beans handle multithreading also. i mean lets say i get 30-40 messages in a minute on my queue. then what would be the behaviour of MDB's. will it pass all those messages to OnMessage , if yes then i guess i will have to write my threading code in OnMessage where i assign task of each message to a new thread so that my MDB is free to get next message, right ?
please clear my doubts if u can.
thanks once again
hi lakshamanam,
there are two problems with my code.
if i run a infinite while loop in run() the cPU USAGE becomes 100%.
and second as u said abt the daemon threadthing, i dont want my MessagesReciever to Stop. It should run forever once started since my application is real time, it will be deployed with MessaageReceiver started and then it should be ready to listen for messages on the queue forever.
thanks
My Requirement

my Application is deployed on JBOSS which has its JMS. now lets say i have defined a Queue named "MyAppQueue" and i know that all the senders whereever they may be will post there messages on this queue.

Now my responsibility is to write a MessageReceiver which is continously running and checking this queue for messages. whenever it receives a message it immidiately calls the messagesListener which processes the message.

So sow my requirement of Writing such MessageReceiver is that , it should always be in running mode(that means once i start it, it starts forever since this is going to be a REal time application) and continously checking the queue, as soon as some message comes it calls messageListener. and also that this messageReceiver should be fast , i mean coz many messages may come at once say 40-50 messages in a minute.
so please tell me how do i now write this MessageReceiver.

the way i have written
My Code


package test.jms;

import java.util.Properties;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


public class MyThreadReceiver implements Runnable{
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver queueReceiver = null;
TextMessage message = null;
MyQueueListener myQueueListener = new MyQueueListener();

/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
String j;
public void run() {
// TODO Auto-generated method stub
while(true){
try {
// Thread.sleep(10000);


}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public static void main(String[] args) {
MyThreadReceiver myReceiver = new MyThreadReceiver();
myReceiver.establishConnection();

/* after connection is established to the queue, i am not closing the connection.i am making a thread and passing my class object to it and in run method i have written while(true ) loop to somehow make my MessageReceiver program run indefinately.. */


Thread thread = new Thread(myReceiver);
thread.start();
System.out.println("finished");
}
/**
this method opens connection to the queue. and i am not closing this connection .
*/
private void establishConnection(){
queueName = "queue/testQueue";
try {
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
jndiContext = new InitialContext();
}catch (NamingException e) {
System.out.println("Could not create JNDI API " + "context: " + e.toString());
System.exit(1);
}
try {
queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
}catch (NamingException e) {
System.out.println("JNDI API lookup failed: " + e.toString());
System.exit(1);
}
try {
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
queueReceiver.setMessageListener(myQueueListener);
queueConnection.start();
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
//if (queueConnection != null) {
//try {
//queueConnection.close();
//}catch (JMSException e) {}
//}

}
}


}




please correct my code. thanks in advance
ok valentin, thanks for you r help , will look into MDB , though till now i was only trying with simple jms api , and was planning to write my MessageReceiver as a Multithreaded application
>Hi Rahul,
>Please help me to understand one thing. You�ve saying that you have an >Web application deployed on JBoss, which uses it�s own JMS system, >probably the JBoss specific one. On the other hand, you have a B2B >application which sends/posts messages to its own JMS system, which is >maybe another JMS implementation like IBM MQ, or BEA-JMS, or whatever. My >question is this: are they really distinct and separate message systems? >Does the first application publishes messages in its own JMS environment >and expects to receive them from there? Or is it possible to have the >JBoss app sends/posts messages to the B2B app�s message systems and >receives those in its own message system (and the other way around)?
>Regards


Hi valentin , first of all thanks for replying. ok this all sounds very confusing . Lets simplyfy it
For the time being lets just say there is my Application deployed on JBOSS which has its JMS. now lets say i have defined a Queue named "MyAppQueue" and i know that all the senders whereever they may be will post there messages on this queue.

Now my responsibility is to write a MessageReceiver which is continously running and checking this queue for messages. whenever it receives a message it immidiately calls the messagesListener which processes the message.

So sow my requirement of Writing such MessageReceiver is that , it should always be in running mode(that means once i start it, it starts forever since this is going to be a REal time application) and continously checking the queue, as soon as some message comes it calls messageListener. and also that this messageReceiver should be fast , i mean coz many messages may come at once say 40-50 messages in a minute.
so please tell me how do i now write this MessageReceiver.

This will solve all my problems.
thanks in advance
Hi friends, i felt probabaly i wasnt clear in explaining my requirement so in order to clear the confusion i wil try to explain it more .

please do read it .

see i have a web application that will be deployed on Jboss.
so i read data from that web app and stuff it into some message and post it to JMS.. this is one end. so i write a MessageSender which connects to JMS and posts it in say queue or topic.

now on other end , i have web methods B2B product installed on some other system , now Web Methods B2B has its own JMS. now i need to write a MessageReceiver in this product which is listening after fixed interval of time to either queue or topic whatever i had used in my WEBAPP .as soon as some messages is posted it reads that message and operates on it.

Similarly the reverse part. that means i have a MessageSender at webMethods end which generates Messages and posts it to Queue or Topic in its JMS. so now i want a MessageReceiver in My WebAPP deployed in JBOSS, which is listening to webMethods JBOSS after fixed interval of time. if some message is posted on particular queue or topic then it collects that and operates on it.

so i need to know , what messaging type do i use. i.e,
(point-to-point) -> Queue
(Publish - Subscribe) Topic

and also how to write the MessageReceiver.. use what , like can it be done with Multi-Threading . etc
please suggest me a nice approach..

and most importantly this all is going to happen real-time.
thanks.
Hello friends,
i am new to JMS.
i have a scenario and not am not able to decide the approach to take for it . Please do read it as many of you might already have implemented it .

I have to design a system where in there will be two jms on two different systems running. so for both the systems i will have to define Sender and receiver.

Now the approach would be something like , if one of the JMS sends some messages lets say in xml format then the other JMS should be able to immidiately receive that mesage and operate on it and vice versa.

so my problems and confusions are .
1)
what type of messaging to use .
Point to Point , or public - subscribe. i mean if say the other JMS sends me a message , then after two seconds it again send some message , and my JMS listened to it only after a minutes then it sould be able to get both messages and should be able to operate on it.

2 Writing sender is fine because that will be based on some action
(if the point 1 is clear i.e where to register the message queue or topic)
However i am confused in writing receiver . How do i continously listen to a jms so that i can read if some message had come and work on that message. and if two messages or say n messages had come then read those messages and operate on them.

So important thing here is my Receiver is continously listening on both the JMS's for the messages.

Please do help me with this. I dont want code but just an approach that solves all this .

Thanks in advance.