Commit b3e3da3d by Adi Amir

make RMQServer work with a test

parent b8a6ea54
......@@ -9,13 +9,13 @@ sourceCompatibility = 1.8
repositories {
//mavenCentral()
maven { url "http://172.16.1.132:8081/repository/internal" }
maven { url "http://mandubian-mvn.googlecode.com/svn/trunk/mandubian-mvn/repository" }
}
}
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.ipgallery.common:utils:1.0.0'
compile 'com.ipgallery.common:utils:1.1.2'
compile 'com.ipgallery.common:itc:1.0.0'
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;
import rabbitmq.common.RMQMessage;
import rabbitmq.common.RMQRestRequest;
import rabbitmq.common.RMQTextMessage;
import utils.http.simpleHttpClient.SimpleHttpRequest.Method;
import utils.http.simpleRestClient.SimpleRestResponse;
import http.simpleHttpClient.SimpleHttpRequest.Method;
import http.simpleRestClient.SimpleRestResponse;
public class RMQRestClient extends RMQClient {
......
......@@ -36,7 +36,7 @@ public class ConnectionWrapper
private Channel createChannel(final String queueName, final Connection connection) throws IOException
{
Channel channel = connection.createChannel();
channel.queueDeclare(queueName, false, false, false, null);
channel.queueDeclare(queueName, true, false, false, null);
return channel;
}
......
......@@ -10,8 +10,9 @@ import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import itm.ITMMessage;
import rabbitmq.common.RMQId;
import utils.itm.ITMMessage;
//import utils.itm.ITMMessage;
public class RMQMessage extends ITMMessage implements Serializable {
......@@ -45,6 +46,17 @@ public class RMQMessage extends ITMMessage implements Serializable {
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 {
JsonToken token = null;
......@@ -85,13 +97,6 @@ public class RMQMessage extends ITMMessage implements Serializable {
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 {
String[] result = new String[2];
......
......@@ -5,7 +5,7 @@ import java.io.Serializable;
import java.io.StringWriter;
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.JsonGenerator;
......
......@@ -9,9 +9,7 @@ public abstract class RMQHandler {
protected RMQId listenerRmqId = null;
protected String apiContextPath = null;
public RMQHandler()
{
}
public RMQHandler(RMQId listenerRmqId, String apiContextPath)
{
......
......@@ -32,9 +32,9 @@ import com.rabbitmq.client.ShutdownSignalException;
//import rabbitmq.reciever.RMQMessage;
import rabbitmq.common.RMQReciever;
import rabbitmq.common.RMQTextMessage;
import utils.common.SimpleLogger;
import utils.itm.ITMManager;
import utils.itm.ITMThread;
import common.SimpleLogger;
import itm.ITMManager;
import itm.ITMThread;
public class RMQServer extends ITMManager {
......
......@@ -7,7 +7,7 @@ import java.util.logging.Level;
import com.fasterxml.jackson.core.JsonParseException;
import rabbitmq.common.*;
import utils.itm.ITMThread;
import itm.ITMThread;
public class RMQThread extends ITMThread
{
......
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 static void main(String[] args) throws IOException, ClassNotFoundException, ShutdownSignalException, ConsumerCancelledException, InterruptedException {
//
//// RMQServerWrapper server = new RMQServerWrapper("MyQueue", "localhost");
//// byte[] recieveMessage = server.recieveMessage();
////
//// ByteArrayInputStream bis = new ByteArrayInputStream(recieveMessage);
////
//// ObjectInput in = new ObjectInputStream(bis);
//// Object readObject;
//// try {
//// readObject = in.readObject();
//// } finally {
//// }
////
//// ModelHierarchy deserializedCar = (ModelHierarchy)readObject;
// }
public static void main(String[] args) throws IOException, ClassNotFoundException, ShutdownSignalException, ConsumerCancelledException, InterruptedException {
int i = 0;
RMQServer mbiServer = new RMQServer();
Boolean bSuccess = mbiServer.Init("testApp",
"/logs",
"myFirstQ@localhost",
1,
100);
if (bSuccess == false) {
System.out.println("failed to mbiServer.Init()");
return;
}
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