Search in sources :

Example 1 with ConsoleLogger

use of com.creditease.monitor.log.ConsoleLogger 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)

Example 2 with ConsoleLogger

use of com.creditease.monitor.log.ConsoleLogger in project uavstack by uavorg.

the class DoTestRocketmqProxy 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);
    RocketmqHookProxy p = new RocketmqHookProxy("test", Collections.emptyMap());
    p.doInstallDProxy(null, "testApp");
    DefaultMQProducer producer = new DefaultMQProducer("hookTest");
    producer.setNamesrvAddr("127.0.0.1:9876");
    try {
        producer.start();
        for (int i = 0; i < 100; i++) {
            Message msg = new Message("SELF_TEST_TOPIC", (i + "").getBytes());
            producer.send(msg);
        }
    } catch (MQClientException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RemotingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MQBrokerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    DefaultMQPushConsumer pushConsumer = new DefaultMQPushConsumer("hookTest1");
    pushConsumer.setNamesrvAddr("127.0.0.1:9876");
    pushConsumer.setMessageModel(MessageModel.BROADCASTING);
    pushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    pushConsumer.registerMessageListener(new MessageListenerOrderly() {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            System.out.println("Consumer1 " + count1++);
            System.out.println(new String(msgs.get(0).getBody()));
            // TODO Auto-generated method stub
            return ConsumeOrderlyStatus.SUCCESS;
        }
    });
    pushConsumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
            System.out.println("Consumer1 " + count1++);
            System.out.println(new String(msgs.get(0).getBody()));
            // TODO Auto-generated method stub
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });
    try {
        pushConsumer.subscribe("SELF_TEST_TOPIC", "*");
        pushConsumer.start();
    } catch (MQClientException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    DefaultMQPushConsumer pushConsumer2 = new DefaultMQPushConsumer("hookTest2");
    pushConsumer2.setNamesrvAddr("127.0.0.1:9876");
    pushConsumer2.setMessageModel(MessageModel.BROADCASTING);
    pushConsumer2.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    pushConsumer2.registerMessageListener(new MessageListenerOrderly() {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            System.out.println("Consumer2 " + count2++);
            System.out.println(new String(msgs.get(0).getBody()));
            // TODO Auto-generated method stub
            return ConsumeOrderlyStatus.SUCCESS;
        }
    });
    pushConsumer2.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
            System.out.println("Consumer2 " + count2++);
            System.out.println(new String(msgs.get(0).getBody()));
            // TODO Auto-generated method stub
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });
    try {
        pushConsumer2.subscribe("SELF_TEST_TOPIC", "*");
        pushConsumer2.start();
    } catch (MQClientException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // pullConsumer.shutdown();
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    pushConsumer.shutdown();
    producer.shutdown();
}
Also used : MessageListenerConcurrently(com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently) Message(com.alibaba.rocketmq.common.message.Message) MessageListenerOrderly(com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly) MQBrokerException(com.alibaba.rocketmq.client.exception.MQBrokerException) ConsumeConcurrentlyStatus(com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus) RocketmqHookProxy(com.creditease.uav.hook.rocketmq.RocketmqHookProxy) DefaultMQPushConsumer(com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer) ConsumeOrderlyContext(com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext) DefaultMQProducer(com.alibaba.rocketmq.client.producer.DefaultMQProducer) ConsumeConcurrentlyContext(com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext) MessageExt(com.alibaba.rocketmq.common.message.MessageExt) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger) ConsumeOrderlyStatus(com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus) RemotingException(com.alibaba.rocketmq.remoting.exception.RemotingException) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException)

Example 3 with ConsoleLogger

use of com.creditease.monitor.log.ConsoleLogger in project uavstack by uavorg.

the class DoTestAredisHookProxy method main.

public static void main(String[] args) throws InterruptedException {
    ConsoleLogger cl = new ConsoleLogger("test");
    cl.setDebugable(true);
    UAVServer.instance().setLog(cl);
    UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
    @SuppressWarnings("rawtypes") AredisHookProxy p = new AredisHookProxy("test", new HashMap());
    p.doProxyInstall(null, "test");
    SystemLogger.init("DEBUG", true, 0);
    CacheManager cm = CacheManagerFactory.build("localhost:6379", 1, 5, 5);
    cm.put("TEST", "foo", "bar");
    String v = cm.get("TEST", "foo");
    System.out.println(v);
    Thread.sleep(1000l);
    cm.shutdown();
}
Also used : HashMap(java.util.HashMap) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger) CacheManager(com.creditease.uav.cache.api.CacheManager)

Example 4 with ConsoleLogger

use of com.creditease.monitor.log.ConsoleLogger in project uavstack by uavorg.

the class DoTestJedisHookProxy method main.

@SuppressWarnings("rawtypes")
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);
    JedisHookProxy p = new JedisHookProxy("test", new HashMap());
    p.doProxyInstall(null, "test");
    foo();
    foo2();
// foo3();
}
Also used : HashMap(java.util.HashMap) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger)

Example 5 with ConsoleLogger

use of com.creditease.monitor.log.ConsoleLogger in project uavstack by uavorg.

the class DoTestLettuceHookProxy method main.

@SuppressWarnings("rawtypes")
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);
    LettuceHookProxy p = new LettuceHookProxy("test", new HashMap());
    p.doProxyInstall(null, "test");
    // foo();
    // foo2();
    // foo3();
    testSync();
    testAsync();
}
Also used : HashMap(java.util.HashMap) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger)

Aggregations

ConsoleLogger (com.creditease.monitor.log.ConsoleLogger)10 HashMap (java.util.HashMap)4 DefaultMQPushConsumer (com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer)1 ConsumeConcurrentlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext)1 ConsumeConcurrentlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus)1 ConsumeOrderlyContext (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyContext)1 ConsumeOrderlyStatus (com.alibaba.rocketmq.client.consumer.listener.ConsumeOrderlyStatus)1 MessageListenerConcurrently (com.alibaba.rocketmq.client.consumer.listener.MessageListenerConcurrently)1 MessageListenerOrderly (com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly)1 MQBrokerException (com.alibaba.rocketmq.client.exception.MQBrokerException)1 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)1 DefaultMQProducer (com.alibaba.rocketmq.client.producer.DefaultMQProducer)1 Message (com.alibaba.rocketmq.common.message.Message)1 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)1 RemotingException (com.alibaba.rocketmq.remoting.exception.RemotingException)1 CECXFClient (com.creditease.monitorframework.fat.client.CECXFClient)1 TestService (com.creditease.monitorframework.fat.client.TestService)1 TestService_Service (com.creditease.monitorframework.fat.client.TestService_Service)1 CacheManager (com.creditease.uav.cache.api.CacheManager)1 HttpAsyncClientHookProxy (com.creditease.uav.hook.httpclients.async.HttpAsyncClientHookProxy)1