Search in sources :

Example 1 with RabbitmqHookProxy

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();
    }
}
Also used : DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Channel(com.rabbitmq.client.Channel) Connection(com.rabbitmq.client.Connection) RabbitmqHookProxy(com.creditease.uav.hook.rabbitmq.RabbitmqHookProxy) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Envelope(com.rabbitmq.client.Envelope) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) DefaultConsumer(com.rabbitmq.client.DefaultConsumer) Consumer(com.rabbitmq.client.Consumer) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

ConsoleLogger (com.creditease.monitor.log.ConsoleLogger)1 RabbitmqHookProxy (com.creditease.uav.hook.rabbitmq.RabbitmqHookProxy)1 Channel (com.rabbitmq.client.Channel)1 Connection (com.rabbitmq.client.Connection)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 Consumer (com.rabbitmq.client.Consumer)1 DefaultConsumer (com.rabbitmq.client.DefaultConsumer)1 Envelope (com.rabbitmq.client.Envelope)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 TimeoutException (java.util.concurrent.TimeoutException)1