Commit b3e3da3d by Adi Amir

make RMQServer work with a test

parent b8a6ea54
...@@ -9,13 +9,13 @@ sourceCompatibility = 1.8 ...@@ -9,13 +9,13 @@ sourceCompatibility = 1.8
repositories { repositories {
//mavenCentral() //mavenCentral()
maven { url "http://172.16.1.132:8081/repository/internal" } maven { url "http://172.16.1.132:8081/repository/internal" }
maven { url "http://mandubian-mvn.googlecode.com/svn/trunk/mandubian-mvn/repository" } }
}
dependencies { dependencies {
compile 'com.rabbitmq:amqp-client:3.6.0' //'com.rabbitmq:rabbitmq-client:1.3.0' //compile 'com.google.gdata:core:1.47.1:core-1.47.1'
compile 'com.rabbitmq:amqp-client:3.6.3' //'com.rabbitmq:rabbitmq-client:1.3.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.2.3' compile 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
compile 'com.ipgallery.common:utils:1.0.0' compile 'com.ipgallery.common:utils:1.1.2'
compile 'com.ipgallery.common:itc:1.0.0' compile 'com.ipgallery.common:itc:1.0.0'
testCompile group: 'junit', name: 'junit', version: '4.11' testCompile group: 'junit', name: 'junit', version: '4.11'
} }
......
{
"oc": 1000,
"key": "key00001",
"APP": "testApp",
"METHOD": "GET",
"ENTITY": "transpotation",
"PARAMS": "/street",
"REQUEST_PARAMS": "ts=0",
"CONTENT": null
}
\ No newline at end of file
...@@ -11,8 +11,8 @@ import rabbitmq.common.RMQKeyGenerator; ...@@ -11,8 +11,8 @@ import rabbitmq.common.RMQKeyGenerator;
import rabbitmq.common.RMQMessage; import rabbitmq.common.RMQMessage;
import rabbitmq.common.RMQRestRequest; import rabbitmq.common.RMQRestRequest;
import rabbitmq.common.RMQTextMessage; import rabbitmq.common.RMQTextMessage;
import utils.http.simpleHttpClient.SimpleHttpRequest.Method; import http.simpleHttpClient.SimpleHttpRequest.Method;
import utils.http.simpleRestClient.SimpleRestResponse; import http.simpleRestClient.SimpleRestResponse;
public class RMQRestClient extends RMQClient { public class RMQRestClient extends RMQClient {
......
...@@ -36,7 +36,7 @@ public class ConnectionWrapper ...@@ -36,7 +36,7 @@ public class ConnectionWrapper
private Channel createChannel(final String queueName, final Connection connection) throws IOException private Channel createChannel(final String queueName, final Connection connection) throws IOException
{ {
Channel channel = connection.createChannel(); Channel channel = connection.createChannel();
channel.queueDeclare(queueName, false, false, false, null); channel.queueDeclare(queueName, true, false, false, null);
return channel; return channel;
} }
......
...@@ -10,8 +10,9 @@ import com.fasterxml.jackson.core.JsonFactory; ...@@ -10,8 +10,9 @@ import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.JsonToken;
import itm.ITMMessage;
import rabbitmq.common.RMQId; import rabbitmq.common.RMQId;
import utils.itm.ITMMessage; //import utils.itm.ITMMessage;
public class RMQMessage extends ITMMessage implements Serializable { public class RMQMessage extends ITMMessage implements Serializable {
...@@ -45,6 +46,17 @@ public class RMQMessage extends ITMMessage implements Serializable { ...@@ -45,6 +46,17 @@ public class RMQMessage extends ITMMessage implements Serializable {
return doParse(parser); return doParse(parser);
} }
public String getParameterByName(String name) {
if (parameters != null)
return parameters.get(name);
else
return null;
}
public Map<String, String> getParameters() {
return parameters;
}
protected boolean doParse(JsonParser parser) throws JsonParseException, IOException { protected boolean doParse(JsonParser parser) throws JsonParseException, IOException {
JsonToken token = null; JsonToken token = null;
...@@ -85,13 +97,6 @@ public class RMQMessage extends ITMMessage implements Serializable { ...@@ -85,13 +97,6 @@ public class RMQMessage extends ITMMessage implements Serializable {
parameters.put(name, value); parameters.put(name, value);
} }
public String getParameterByName(String name) {
if (parameters != null)
return parameters.get(name);
else
return null;
}
protected String[] getNextField(JsonParser parser) throws JsonParseException, IOException { protected String[] getNextField(JsonParser parser) throws JsonParseException, IOException {
String[] result = new String[2]; String[] result = new String[2];
......
...@@ -5,7 +5,7 @@ import java.io.Serializable; ...@@ -5,7 +5,7 @@ import java.io.Serializable;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Map.Entry; import java.util.Map.Entry;
import utils.http.simpleHttpClient.SimpleHttpRequest.Method; import http.simpleHttpClient.SimpleHttpRequest.Method;
import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;
......
...@@ -9,9 +9,7 @@ public abstract class RMQHandler { ...@@ -9,9 +9,7 @@ public abstract class RMQHandler {
protected RMQId listenerRmqId = null; protected RMQId listenerRmqId = null;
protected String apiContextPath = null; protected String apiContextPath = null;
public RMQHandler()
{
}
public RMQHandler(RMQId listenerRmqId, String apiContextPath) public RMQHandler(RMQId listenerRmqId, String apiContextPath)
{ {
......
...@@ -32,9 +32,9 @@ import com.rabbitmq.client.ShutdownSignalException; ...@@ -32,9 +32,9 @@ import com.rabbitmq.client.ShutdownSignalException;
//import rabbitmq.reciever.RMQMessage; //import rabbitmq.reciever.RMQMessage;
import rabbitmq.common.RMQReciever; import rabbitmq.common.RMQReciever;
import rabbitmq.common.RMQTextMessage; import rabbitmq.common.RMQTextMessage;
import utils.common.SimpleLogger; import common.SimpleLogger;
import utils.itm.ITMManager; import itm.ITMManager;
import utils.itm.ITMThread; import itm.ITMThread;
public class RMQServer extends ITMManager { public class RMQServer extends ITMManager {
......
...@@ -7,7 +7,7 @@ import java.util.logging.Level; ...@@ -7,7 +7,7 @@ import java.util.logging.Level;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import rabbitmq.common.*; import rabbitmq.common.*;
import utils.itm.ITMThread; import itm.ITMThread;
public class RMQThread extends ITMThread public class RMQThread extends ITMThread
{ {
......
package rabbitmq.impl; package rabbitmq.impl;
import com.rabbitmq.client.ConsumerCancelledException;
import com.rabbitmq.client.ShutdownSignalException;
import rabbitmq.common.RMQId;
import rabbitmq.server.RMQHandler;
import rabbitmq.server.RMQServer;
import java.io.IOException;
public class Receiver { public class Receiver {
// public static void main(String[] args) throws IOException, ClassNotFoundException, ShutdownSignalException, ConsumerCancelledException, InterruptedException { public static void main(String[] args) throws IOException, ClassNotFoundException, ShutdownSignalException, ConsumerCancelledException, InterruptedException {
//
//// RMQServerWrapper server = new RMQServerWrapper("MyQueue", "localhost"); int i = 0;
//// byte[] recieveMessage = server.recieveMessage();
//// RMQServer mbiServer = new RMQServer();
//// ByteArrayInputStream bis = new ByteArrayInputStream(recieveMessage); Boolean bSuccess = mbiServer.Init("testApp",
//// "/logs",
//// ObjectInput in = new ObjectInputStream(bis); "myFirstQ@localhost",
//// Object readObject; 1,
//// try { 100);
//// readObject = in.readObject(); if (bSuccess == false) {
//// } finally { System.out.println("failed to mbiServer.Init()");
//// } return;
//// }
//// ModelHierarchy deserializedCar = (ModelHierarchy)readObject;
// } RMQHandler rmqHandler = new TestRMQHandler(new RMQId("myFirstQ@localhost"), "testApp");
mbiServer.setHandler(rmqHandler);
mbiServer.Run();
}
} }
package rabbitmq.impl;
import rabbitmq.common.RMQId;
import rabbitmq.common.RMQMessage;
import rabbitmq.server.RMQHandler;
import java.util.Iterator;
import java.util.Map;
/**
* Created by adi on 18/07/16.
*/
public class TestRMQHandler extends RMQHandler {
public TestRMQHandler(RMQId listenerRmqId, String apiContextPath)
{
super(listenerRmqId, apiContextPath);
}
public void handleRequest(RMQMessage message) {
String msg = "Received nsg: ";
msg += " oc:" + message.getOpCode();
msg += " key:" + message.getKey();
Map<String, String> paramsMap = message.getParameters();
Iterator it = paramsMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
msg += " " + entry.getKey() + ":" + entry.getValue();
}
System.out.println(msg);
}
}
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