use of com.creditease.uav.hook.rabbitmq.RabbitmqHookProxy in project uavstack by uavorg.
the class DoTestRabbitmqProxy method main.
public static void main(String[] args) {
ConsoleLogger cl = new ConsoleLogger("test");
cl.setDebugable(true);
UAVServer.instance().setLog(cl);
UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
RabbitmqHookProxy p = new RabbitmqHookProxy("test", Collections.emptyMap());
p.doInstallDProxy(null, "testApp");
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setHost("127.0.0.1");
factory.setPort(5672);
try {
conn = factory.newConnection();
channel = conn.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
channel.queueDeclare("aaa", false, false, false, null);
new Thread(new Runnable() {
@Override
public void run() {
String message = "Hello World!";
while (true) {
try {
channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
// System.out.println(" [x] Sent '" + message + "'");
channel.basicPublish("", "aaa", null, "aaame".getBytes("UTF-8"));
// System.out.println(" [x] Sent 'aaame'");
Thread.sleep(1000);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
Connection connection = factory.newConnection();
Channel recvchannel = connection.createChannel();
recvchannel.queueDeclare(QUEUE_NAME, false, false, false, null);
recvchannel.queueDeclare("aaa", false, false, false, null);
Consumer consumer = new DefaultConsumer(recvchannel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
String message = new String(body, "UTF-8");
// System.out.println(" [x] Received '" + message + "'1");
}
};
recvchannel.basicConsume(QUEUE_NAME, true, consumer);
String consumerTag = recvchannel.basicConsume("aaa", true, consumer);
try {
Thread.sleep(50000);
recvchannel.basicCancel(consumerTag);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TimeoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations