building reliable server/client - help needed
delboypass May 19, 2003 6:06 AMCURRENT SCENARIO
-----------------------------------
I have a bean set-up on a remote machine.
This bean is setup to lookup the JNDI tree on the remote machine. (Specifically to get hte queueconnectionfactory)
What we are currently trying to do is to get the bean to save a generated message to the remote queue when the server is down.
On the remote Bean on create we set up the variables for everything.
See code below. What this enables is that the remote bean gets all the configuration on start up from the server. Then if the server goes down, it cant send a message anymore. Through this configuration, there should be the remote queue (Queue/testqueue) and the server queue (Queue/testqueue) and if the remote bean finds the server down writes the message to the remote local queue but if hte server is up the message is sent to the server queue waiting to be consumed.
REAL QUESTION
-------------------------
What I need to be able to do is to be able to reconnect the remote bean back to the server when it recognises that the server is back up and also persist the message that it was unable to deliver to the server on its own local queue, Queue/testqueue. (How to recognise that the server is down or does the jms implementation do that for us and the reconnection??How to manage the two identical queues on each machine so that they only hold a message in one or the other queues)
What is the best way to be able to do this as perhaps the way in which im trying to do it is not the best (IE setting up the bean oncreate).
Any test code available would be most useful.
// remote bean code//
try {
InitialContext ic = new InitialContext();
q = (Queue)ic.lookup("queue/testQueue");
Context c = (Context) ic.lookup("java:/comp/env");
qcf = (QueueConnectionFactory)c.lookup( "QueFactory" );
} catch (NamingException e) {}
try {
qc = qcf.createQueueConnection();
} catch (JMSException e) {}
try {
qs = qc.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
} catch (JMSException e) {}
try {
qsend = qs.createSender(q);
} catch (JMSException e) {}
}
//sending a message
public String sendMsg(String msg)
{
TextMessage ms = null;
try {
ms = qs.createTextMessage();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
Date timeStamp= new Date();
ms.setText("MDB message from queueService: "+ msg+ "\n" + df.format(timeStamp));
qsend.send(ms, DeliveryMode.PERSISTENT, 2, 1000000);
} catch (JMSException e) {}
return "Message sent";
}
//end of remote bean code//