Commit 6fbbf406 by Adi Amir

general improvements in server side

parent b3e3da3d
group 'com.ipgallery.common' group 'com.ipgallery.common'
version '1.0.0' version '1.0.x'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
......
{ {
"oc": 1000, "oc": 1000,
"key": "key00001", "key": "key00001",
"APP": "testApp", "oId": "respQ@localhost",
"APP": "test",
"METHOD": "GET", "METHOD": "GET",
"ENTITY": "transpotation", "ENTITY": "transpotation",
"PARAMS": "/street", "PARAMS": "/street",
"REQUEST_PARAMS": "ts=0", "REQUEST_PARAMS": "ts=0",
"CONTENT": null "CONTENT": null
} }
\ No newline at end of file \ No newline at end of file
...@@ -36,8 +36,11 @@ import common.SimpleLogger; ...@@ -36,8 +36,11 @@ import common.SimpleLogger;
import itm.ITMManager; import itm.ITMManager;
import itm.ITMThread; import itm.ITMThread;
import static java.lang.Thread.sleep;
public class RMQServer extends ITMManager { public class RMQServer extends ITMManager {
private final static Integer CONNECTION_RETRY_TIMEOUT = 10000;
protected RMQReciever mRMQReciever = null; protected RMQReciever mRMQReciever = null;
protected RMQId listenRMQId = null; protected RMQId listenRMQId = null;
protected SimpleLogger logger = null; protected SimpleLogger logger = null;
...@@ -96,15 +99,17 @@ public class RMQServer extends ITMManager { ...@@ -96,15 +99,17 @@ public class RMQServer extends ITMManager {
mRMQReciever.purge(); mRMQReciever.purge();
} }
logger.log(Level.INFO, "Connected successfully to: " + listenRMQId.getDescriptor());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
logSevere("RMQServer::InitListenQ", "InitListenQ() failed", e); logSevere("RMQServer::InitListenQ", "failed on rmqId: " + listenRMQId.getDescriptor() + " e:", e);
return false; return false;
} }
catch (TimeoutException e) { catch (TimeoutException e) {
e.printStackTrace(); e.printStackTrace();
logSevere("RMQServer::InitListenQ", "InitListenQ() failed on timeout", e); logSevere("RMQServer::InitListenQ", "failed on rmqId: "+ listenRMQId.getDescriptor() + " e:", e);
return false; return false;
} }
return true; return true;
...@@ -132,7 +137,17 @@ public class RMQServer extends ITMManager { ...@@ -132,7 +137,17 @@ public class RMQServer extends ITMManager {
public void HandleMsg() throws ClassNotFoundException, IOException public void HandleMsg() throws ClassNotFoundException, IOException
{ {
try { try {
// wait for message to arrive if (mRMQReciever == null) {
// failed to create a receiver at initialization stage
// retry untill we succeeded
logger.log(Level.INFO, "Trying to connect to: " + listenRMQId.getDescriptor() + "...");
if (InitListenQ() == false) {
sleep(CONNECTION_RETRY_TIMEOUT);
return;
}
}
// wait for message to arrive ...
RMQTextMessage rmqMsg = mRMQReciever.recieveTextMessageWithProps(0); RMQTextMessage rmqMsg = mRMQReciever.recieveTextMessageWithProps(0);
// parse the message, but only the basic fields needed for routing // parse the message, but only the basic fields needed for routing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment