Commit 55ce5d33 by Adi Amir

complete debugging rabbit server side

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