Commit 55ce5d33 by Adi Amir

complete debugging rabbit server side

parent 08a751a1
...@@ -25,6 +25,7 @@ import microservice.params.RestServerParams; ...@@ -25,6 +25,7 @@ import microservice.params.RestServerParams;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
import rabbitmq.common.RMQId;
import rabbitmq.server.RMQHandler; import rabbitmq.server.RMQHandler;
import rabbitmq.server.RMQServer; import rabbitmq.server.RMQServer;
...@@ -277,7 +278,11 @@ public class MicroserviceApp ...@@ -277,7 +278,11 @@ public class MicroserviceApp
Set<Entry<String, BaseHandler>> entrySet = this.msMap.entrySet(); Set<Entry<String, BaseHandler>> entrySet = this.msMap.entrySet();
for (Entry<String, BaseHandler> entry : entrySet) for (Entry<String, BaseHandler> entry : entrySet)
{ {
RMQHandler rmqHandler = new MBIHandler(entry.getKey(), entry.getValue()); RMQHandler rmqHandler = new MBIHandler( new RMQId(mbiParams.getListenRMQId()),
entry.getKey(),
entry.getValue(),
getLogger());
if (rmqHandler != null) if (rmqHandler != null)
mbiServer.setHandler(rmqHandler); mbiServer.setHandler(rmqHandler);
} }
......
...@@ -8,10 +8,7 @@ import java.util.Map; ...@@ -8,10 +8,7 @@ import java.util.Map;
import microservice.RequestContext; import microservice.RequestContext;
import microservice.defs.Constants; import microservice.defs.Constants;
import microservice.defs.Enums.EnumHttpMethod; import microservice.defs.Enums.EnumHttpMethod;
import microservice.io.iface.IContainer; import microservice.io.iface.*;
import microservice.io.iface.INotifyCallback;
import microservice.io.iface.IRequest;
import microservice.io.iface.IResponse;
import microservice.io.impl.IRequestMBIImpl; import microservice.io.impl.IRequestMBIImpl;
import microservice.io.impl.IResponseMBIImpl; import microservice.io.impl.IResponseMBIImpl;
...@@ -19,6 +16,7 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -19,6 +16,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
import rabbitmq.common.RMQId;
import rabbitmq.common.RMQMessage; import rabbitmq.common.RMQMessage;
import rabbitmq.common.RMQRestRequest; import rabbitmq.common.RMQRestRequest;
import rabbitmq.server.RMQHandler; import rabbitmq.server.RMQHandler;
...@@ -26,16 +24,17 @@ import rabbitmq.server.RMQHandler; ...@@ -26,16 +24,17 @@ import rabbitmq.server.RMQHandler;
public class MBIHandler extends RMQHandler implements IContainer public class MBIHandler extends RMQHandler implements IContainer
{ {
public ObjectMapper objMapper = null; public ObjectMapper objMapper = null;
BaseHandler msHandler = null; BaseHandler msHandler = null;
ILogger logger = null;
public MBIHandler(String apiContextPath, BaseHandler msHandler) public MBIHandler(RMQId listenerRmqId, String apiContextPath, BaseHandler msHandler, ILogger logger)
{ {
super(); super(listenerRmqId, apiContextPath);
this.objMapper = new ObjectMapper(); this.objMapper = new ObjectMapper();
this.msHandler = msHandler; this.msHandler = msHandler;
this.msHandler.setObjMapper(objMapper); this.msHandler.setObjMapper(objMapper);
this.apiContextPath = apiContextPath; this.apiContextPath = apiContextPath;
this.logger = logger;
} }
@Override @Override
...@@ -79,7 +78,7 @@ public class MBIHandler extends RMQHandler implements IContainer ...@@ -79,7 +78,7 @@ public class MBIHandler extends RMQHandler implements IContainer
} }
else else
{ {
IResponse iResp = new IResponseMBIImpl(request, listenerRmqId); IResponse iResp = new IResponseMBIImpl(request, listenerRmqId, logger);
sendErrorResp(iResp,Constants.FAILED_TO_GET_PARAMS); sendErrorResp(iResp,Constants.FAILED_TO_GET_PARAMS);
} }
} }
...@@ -94,7 +93,7 @@ public class MBIHandler extends RMQHandler implements IContainer ...@@ -94,7 +93,7 @@ public class MBIHandler extends RMQHandler implements IContainer
RequestContext reqCtx = new RequestContext(); RequestContext reqCtx = new RequestContext();
reqCtx.container = this; reqCtx.container = this;
reqCtx.request = new IRequestMBIImpl(request); reqCtx.request = new IRequestMBIImpl(request);
reqCtx.response = new IResponseMBIImpl(request, listenerRmqId); reqCtx.response = new IResponseMBIImpl(request, listenerRmqId, logger);
reqCtx.objMapper = this.objMapper; reqCtx.objMapper = this.objMapper;
/* /*
* params * params
......
...@@ -13,7 +13,8 @@ import microservice.io.iface.IRequest; ...@@ -13,7 +13,8 @@ import microservice.io.iface.IRequest;
public class IRequestMBIImpl implements IRequest public class IRequestMBIImpl implements IRequest
{ {
RMQMessage rmqRequest; RMQMessage rmqRequest;
public IRequestMBIImpl(RMQMessage request) public IRequestMBIImpl(RMQMessage request)
{ {
super(); super();
......
...@@ -3,6 +3,7 @@ package microservice.io.impl; ...@@ -3,6 +3,7 @@ package microservice.io.impl;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import microservice.io.iface.ILogger;
import rabbitmq.common.RMQSender; import rabbitmq.common.RMQSender;
import rabbitmq.common.RMQId; import rabbitmq.common.RMQId;
import rabbitmq.common.RMQMessage; import rabbitmq.common.RMQMessage;
...@@ -13,12 +14,14 @@ public class IResponseMBIImpl implements IResponse ...@@ -13,12 +14,14 @@ public class IResponseMBIImpl implements IResponse
{ {
protected RMQMessage rmqRequest; protected RMQMessage rmqRequest;
protected RMQId listenerRmqId = null; protected RMQId listenerRmqId = null;
protected ILogger logger = null;
public IResponseMBIImpl(RMQMessage request, RMQId listenerRmqId) public IResponseMBIImpl(RMQMessage request, RMQId listenerRmqId, ILogger logger)
{ {
super(); super();
this.rmqRequest = request; this.rmqRequest = request;
this.listenerRmqId = listenerRmqId; this.listenerRmqId = listenerRmqId;
this.logger = logger;
} }
@Override @Override
...@@ -36,13 +39,17 @@ public class IResponseMBIImpl implements IResponse ...@@ -36,13 +39,17 @@ public class IResponseMBIImpl implements IResponse
protected void sendResponseToOrigin(String response) { protected void sendResponseToOrigin(String response) {
try { try {
RMQSender rmqClient = new RMQSender(rmqRequest.getOrigin()); RMQId originId = rmqRequest.getOrigin();
if (originId != null) {
RMQRestResponse restResponse = new RMQRestResponse(); RMQSender rmqClient = new RMQSender(originId);
restResponse.setContent(response); RMQRestResponse restResponse = new RMQRestResponse();
rmqClient.sendMessage(response, listenerRmqId); restResponse.setContent(response);
rmqClient.sendMessage(response, listenerRmqId);
}
else
logger.error("sendResponseToOrigin failed() - no originId was specified");
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block logger.error("sendResponseToOrigin failed(). e: " + e.toString());
e.printStackTrace(); e.printStackTrace();
} }
} }
......
...@@ -4,6 +4,9 @@ import java.util.Map; ...@@ -4,6 +4,9 @@ import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import microservice.MicroserviceApp;
import microservice.io.iface.ILogger;
import rabbitmq.common.RMQId;
import rabbitmq.server.RMQHandler; import rabbitmq.server.RMQHandler;
import rabbitmq.server.RMQServer; import rabbitmq.server.RMQServer;
import microservice.handlers.BaseHandler; import microservice.handlers.BaseHandler;
...@@ -18,6 +21,7 @@ public class IRestServerRMQImpl implements IRestServer { ...@@ -18,6 +21,7 @@ public class IRestServerRMQImpl implements IRestServer {
MBIParams mbiParams; MBIParams mbiParams;
RMQServer mbiServer = null; RMQServer mbiServer = null;
Thread mbiThread = null; Thread mbiThread = null;
public IRestServerRMQImpl(MBIParams rmqParams) { public IRestServerRMQImpl(MBIParams rmqParams) {
this.mbiParams = rmqParams; this.mbiParams = rmqParams;
...@@ -38,7 +42,9 @@ public class IRestServerRMQImpl implements IRestServer { ...@@ -38,7 +42,9 @@ public class IRestServerRMQImpl implements IRestServer {
Set<Entry<String, BaseHandler>> entrySet = msHandlersMap.entrySet(); Set<Entry<String, BaseHandler>> entrySet = msHandlersMap.entrySet();
for (Entry<String, BaseHandler> entry : entrySet) for (Entry<String, BaseHandler> entry : entrySet)
{ {
RMQHandler rmqHandler = new MBIHandler(entry.getKey(), entry.getValue()); RMQHandler rmqHandler = new MBIHandler(new RMQId(mbiParams.getListenRMQId()),
entry.getKey(),
entry.getValue(), MicroserviceApp.getsInstance().getLogger());
if (rmqHandler != null) if (rmqHandler != null)
mbiServer.setHandler(rmqHandler); mbiServer.setHandler(rmqHandler);
} }
......
...@@ -19,8 +19,8 @@ public class TestCommandClient { ...@@ -19,8 +19,8 @@ public class TestCommandClient {
public class ASM public class ASM
{ {
String ae = ""; String ae;
String provider = ""; String provider;
public String getAe() { public String getAe() {
return ae; return ae;
} }
...@@ -57,7 +57,7 @@ public class TestCommandClient { ...@@ -57,7 +57,7 @@ public class TestCommandClient {
@Override @Override
protected BaseRestResponse run() throws Exception { protected BaseRestResponse run() throws Exception {
BaseRestResponse brr = new BaseRestResponse(true, null); BaseRestResponse brr = new BaseRestResponse(true, null);
// asm.setAe(reqCtx.getParamsString()); asm.setAe(reqCtx.getParamsString());
System.out.println("set ae to: " + asm.getAe()); System.out.println("set ae to: " + asm.getAe());
return brr; return brr;
} }
......
...@@ -3,10 +3,10 @@ package microservice; ...@@ -3,10 +3,10 @@ package microservice;
import microservice.MicroserviceClient.EnumRestClientType; import microservice.MicroserviceClient.EnumRestClientType;
import microservice.io.iface.ICommandClient; import microservice.io.iface.ICommandClient;
import microservice.io.impl.IRestClientRestImpl; import microservice.io.iface.ILogger;
import microservice.io.impl.IRestServerUndertowImpl; import microservice.io.impl.*;
import microservice.io.impl.IServiceDiscoveryConsulImpl;
import microservice.params.BaseClientParams; import microservice.params.BaseClientParams;
import microservice.params.MBIParams;
import microservice.params.RestClientParams; import microservice.params.RestClientParams;
import microservice.params.RestServerParams; import microservice.params.RestServerParams;
...@@ -25,19 +25,22 @@ public class TestMicroserviceApp { ...@@ -25,19 +25,22 @@ public class TestMicroserviceApp {
BaseClientParams clientParams = new RestClientParams("other-service", true, 10, "localhost:32010","localhost:6379"); BaseClientParams clientParams = new RestClientParams("other-service", true, 10, "localhost:32010","localhost:6379");
final IServiceDiscoveryConsulImpl serDisco = new IServiceDiscoveryConsulImpl("localhost", 8500); final IServiceDiscoveryConsulImpl serDisco = new IServiceDiscoveryConsulImpl("localhost", 8500);
ICommandClient cmdClient = new IRestClientRestImpl(clientParams).withServiceDiscovery(serDisco); ICommandClient cmdClient = new IRestClientRestImpl(clientParams).withServiceDiscovery(serDisco);
new microservice.MicroserviceApp("myService")
.withMetrics()
.withMonitoring()
.withPubSub(new microservice.io.impl.IPubSubMQTTImpl("tcp://localhost",0,null,0))
.withServiceDiscovery(serDisco)
// .addHandler("/mon",new microservice.handlers.MonitorHandler())
.addMicroserviceClient(new MicroserviceClient(cmdClient,clientParams))
//.addMicroserviceClient("rabbit-service",new MicroserviceClient(EnumRestClientType.E_RABBITMQ,clientParams))
.addRestServer(new IRestServerUndertowImpl(new RestServerParams(32000, "172.16.1.244", 2)))
//.addRestServer(new IRestServerRMQImplnew MBIParams("1", 0, 200, "rmq"))
.build()
.run();
String appName = "testApp";
//ILogger logger = new ILogger4jImpl(appName);
microservice.MicroserviceApp msApp = new microservice.MicroserviceApp(appName);
msApp.withMetrics()
//.withLogger(logger)
.withMonitoring()
.withPubSub(new microservice.io.impl.IPubSubMQTTImpl("tcp://localhost",0,null,0))
//.withServiceDiscovery(serDisco)
.addHandler("/test",new TestMicroserviceHandler())
.addMicroserviceClient(new MicroserviceClient(cmdClient,clientParams))
//.addMicroserviceClient("rabbit-service",new MicroserviceClient(EnumRestClientType.E_RABBITMQ,clientParams))
.addRestServer(new IRestServerUndertowImpl(new RestServerParams(32000, "localhost", 2)))
.addRestServer(new IRestServerRMQImpl(new MBIParams("myFirstQ@localhost", 1, 200, "/logs")))
.build()
.run();
} }
} }
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