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",
"METHOD": "GET", "APP": "test",
"ENTITY": "transpotation", "METHOD": "GET",
"PARAMS": "/street", "ENTITY": "transpotation",
"REQUEST_PARAMS": "ts=0", "PARAMS": "/street",
"CONTENT": null "REQUEST_PARAMS": "ts=0",
} "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;
...@@ -95,16 +98,18 @@ public class RMQServer extends ITMManager { ...@@ -95,16 +98,18 @@ public class RMQServer extends ITMManager {
if (isEmptyQueueOnLoad) { if (isEmptyQueueOnLoad) {
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,9 +137,19 @@ public class RMQServer extends ITMManager { ...@@ -132,9 +137,19 @@ 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) {
RMQTextMessage rmqMsg = mRMQReciever.recieveTextMessageWithProps(0); // 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);
// parse the message, but only the basic fields needed for routing // parse the message, but only the basic fields needed for routing
// the message to a worker thread // the message to a worker thread
RMQMessage baseMsg = new RMQMessage(); RMQMessage baseMsg = new RMQMessage();
......
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