5 Commity 655b5fcdb8 ... 7069791936

Autor SHA1 Wiadomość Data
  liutong3 7069791936 msgframe的rabbitmq测试代码 6 lat temu
  liutong3 a6eb637e07 msgframe的rabbitmq测试代码 6 lat temu
  liutong3 a3183fd09e msgframe的rocketmq测试代码 6 lat temu
  liutong3 2876b3a8f4 msgframe的rocketmq测试代码 6 lat temu
  liutong3 effa71799a msgframe的kafka测试代码 6 lat temu

+ 1 - 0
ipu-kafka-example/src/main/java/com/ai/ipu/example/kafka/KafkaProducerExample.java

@ -83,6 +83,7 @@ public class KafkaProducerExample {
83 83
            final MsgFTextMessage message = new MsgFTextMessage();
84 84
            message.setText(text);
85 85
            client.sendOrderMsg(topic, message, orderId);
86
            LOG.debug("Sent:" + message);
86 87
            Thread.currentThread().sleep(1000);
87 88
        } catch (Exception e) {
88 89
            throw new RuntimeException(e);

+ 86 - 0
ipu-rabbitmq-example/pom.xml

@ -0,0 +1,86 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
    <modelVersion>4.0.0</modelVersion>
6
7
    <groupId>com.ai.ipu</groupId>
8
    <artifactId>ipu-rabbitmq-example</artifactId>
9
    <version>1.0-SNAPSHOT</version>
10
11
    <properties>
12
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13
        <ipu>3.1-SNAPSHOT</ipu>
14
        <jdk>1.8</jdk>
15
    </properties>
16
17
    <dependencies>
18
        <dependency>
19
            <groupId>com.ai.aif.msgframe</groupId>
20
            <artifactId>msgframe-common</artifactId>
21
            <version>1.9.2</version>
22
        </dependency>
23
        <dependency>
24
            <groupId>com.ai.aif.msgframe</groupId>
25
            <artifactId>msgframe-client</artifactId>
26
            <version>1.9.2</version>
27
        </dependency>
28
        <dependency>
29
            <groupId>com.ai.aif.msgframe</groupId>
30
            <artifactId>msgframe-server</artifactId>
31
            <version>1.9.2</version>
32
        </dependency>
33
        <dependency>
34
            <groupId>com.ai.aif.msgframe</groupId>
35
            <artifactId>xmlmsgframe</artifactId>
36
            <version>2.6.4</version>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.apache.xmlbeans</groupId>
40
            <artifactId>xmlbeans</artifactId>
41
            <version>2.6.0</version>
42
        </dependency>
43
        <dependency>
44
            <groupId>com.rabbitmq</groupId>
45
            <artifactId>amqp-client</artifactId>
46
            <version>3.6.5</version>
47
        </dependency>
48
        <dependency>
49
            <groupId>com.alibaba</groupId>
50
            <artifactId>fastjson</artifactId>
51
            <version>1.1.46</version>
52
        </dependency>
53
        <dependency>
54
            <groupId>org.hamcrest</groupId>
55
            <artifactId>hamcrest-core</artifactId>
56
            <version>1.3</version>
57
        </dependency>
58
        <dependency>
59
            <groupId>javax.jms</groupId>
60
            <artifactId>jms</artifactId>
61
            <version>1.1</version>
62
        </dependency>
63
        <dependency>
64
            <groupId>org.apache.kafka</groupId>
65
            <artifactId>kafka-clients</artifactId>
66
            <version>0.10.2.0</version>
67
        </dependency>
68
        <dependency>
69
            <groupId>log4j</groupId>
70
            <artifactId>log4j</artifactId>
71
            <version>1.2.12</version>
72
        </dependency>
73
        <dependency>
74
            <groupId>com.alibaba.rocketmq</groupId>
75
            <artifactId>rocketmq-client</artifactId>
76
            <version>3.5.9</version>
77
        </dependency>
78
        <dependency>
79
            <groupId>junit</groupId>
80
            <artifactId>junit</artifactId>
81
            <version>4.12</version>
82
            <scope>compile</scope>
83
        </dependency>
84
    </dependencies>
85
86
</project>

+ 15 - 0
ipu-rabbitmq-example/src/main/java/com/ai/ipu/example/rabbitmq/RabbitMQCustomer.java

@ -0,0 +1,15 @@
1
package com.ai.ipu.example.rabbitmq;
2
3
import com.ai.aif.msgframe.consumer.MfServiceStartup;
4
5
/**
6
 * @author liutong3
7
 * @team IPU
8
 * @date 2019/6/10 17:09
9
 * @desc rabbitmq消费者启动器
10
 */
11
public class RabbitMQCustomer {
12
    public static void main(String[] args){
13
        MfServiceStartup.main();
14
    }
15
}

+ 22 - 0
ipu-rabbitmq-example/src/main/java/com/ai/ipu/example/rabbitmq/RabbitMQCustomerExample.java

@ -0,0 +1,22 @@
1
package com.ai.ipu.example.rabbitmq;
2
3
import com.ai.aif.msgframe.common.IConsumerProcessor;
4
import com.ai.aif.msgframe.common.exception.ConsumerException;
5
import com.ai.aif.msgframe.common.message.MsgFMessage;
6
import com.ai.aif.msgframe.common.message.MsgFTextMessage;
7
8
/**
9
 * @author liutong3
10
 * @team IPU
11
 * @date 2019/6/10 16:20
12
 * @desc rabbitmq消费者
13
 */
14
public class RabbitMQCustomerExample implements IConsumerProcessor {
15
    @SuppressWarnings("rawtypes")
16
    public Object process(MsgFMessage message) throws ConsumerException {
17
        if (message instanceof MsgFTextMessage) {
18
            System.out.println("{topic:" + message.getTopic() + ",value:" + ((MsgFTextMessage) message).getText() + "}");
19
        }
20
        return true;
21
    }
22
}

+ 92 - 0
ipu-rabbitmq-example/src/main/java/com/ai/ipu/example/rabbitmq/RabbitMQProducerExample.java

@ -0,0 +1,92 @@
1
package com.ai.ipu.example.rabbitmq;
2
3
import com.ai.aif.msgframe.MfProducerClient;
4
import com.ai.aif.msgframe.common.CompletionListener;
5
import com.ai.aif.msgframe.common.message.MsgFMessage;
6
import com.ai.aif.msgframe.common.message.MsgFTextMessage;
7
import org.apache.log4j.Logger;
8
import org.junit.Test;
9
10
import java.util.Date;
11
12
13
/**
14
 * @author liutong3
15
 * @team IPU
16
 * @date 2019/6/6 16:07
17
 * @desc rabbitmq生产者
18
 */
19
public class RabbitMQProducerExample {
20
    private static final Logger LOG = Logger.getLogger(RabbitMQProducerExample.class);
21
    private final String TOPIC = "test";
22
    private final String MESSAGE = "test";
23
    private final String ORDERID = "1000";
24
25
    @Test
26
    public void testSendMessage() {
27
        String message = getMessage();
28
        sendMessage(TOPIC, message);
29
    }
30
31
    @Test
32
    public void testSendAsyncMessage() {
33
        String message = getMessage();
34
        sendAsyncMessage(TOPIC, message);
35
    }
36
37
    @Test
38
    public void testSendOrderMessage() {
39
        String message = getMessage();
40
        sendOrderMessage(TOPIC, message, ORDERID);
41
    }
42
43
    private String getMessage() {
44
        return MESSAGE + "_" + new Date().getTime();
45
    }
46
47
    private void sendMessage(String topic, String text) {
48
        try {
49
            MfProducerClient client = new MfProducerClient();
50
            MsgFTextMessage message = new MsgFTextMessage();
51
            message.setText(text);
52
            client.send(topic, message);
53
            LOG.debug("Sent:" + message);
54
            Thread.currentThread().sleep(1000);
55
        } catch (Exception e) {
56
            throw new RuntimeException(e);
57
        }
58
    }
59
60
    private void sendAsyncMessage(String topic, final String text) {
61
        try {
62
            MfProducerClient client = new MfProducerClient();
63
            final MsgFTextMessage message = new MsgFTextMessage();
64
            message.setText(text);
65
            client.asyncSend(topic, message, new CompletionListener() {
66
                public void onCompletion(MsgFMessage msgFMessage) {
67
                    LOG.debug("Sent Success:" + msgFMessage.getMsgId() + "-" + text);
68
                }
69
70
                public void onException(MsgFMessage msgFMessage, Exception e) {
71
                    LOG.debug("Sent Error:" + msgFMessage.getMsgId() + "-" + text);
72
                }
73
            });
74
            Thread.currentThread().sleep(1000);
75
        } catch (Exception e) {
76
            throw new RuntimeException(e);
77
        }
78
    }
79
80
    private void sendOrderMessage(String topic, final String text, String orderId) {
81
        try {
82
            MfProducerClient client = new MfProducerClient();
83
            final MsgFTextMessage message = new MsgFTextMessage();
84
            message.setText(text);
85
            client.sendOrderMsg(topic, message, orderId);
86
            LOG.debug("Sent:" + message);
87
            Thread.currentThread().sleep(1000);
88
        } catch (Exception e) {
89
            throw new RuntimeException(e);
90
        }
91
    }
92
}

+ 8 - 0
ipu-rabbitmq-example/src/main/resources/log4j.properties

@ -0,0 +1,8 @@
1
log4j.rootLogger=error, console
2
log4j.logger.org.apache.zookeeper=error
3
log4j.logger.com.ai.ipu.example=debug
4
5
log4j.appender.console=org.apache.log4j.ConsoleAppender
6
log4j.appender.console.target=System.out
7
log4j.appender.console.layout=org.apache.log4j.PatternLayout
8
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %5p [%t] (%F:%L) - %m%n

+ 22 - 0
ipu-rabbitmq-example/src/main/resources/msgframe-config.xml

@ -0,0 +1,22 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<msgframeCfg xmlns="http://www.asiainfo.com/msgframe">
3
    <centerCfg>
4
        <name>ipu-rabbitmq-example</name>
5
        <destinations>
6
            <queue name="test" belong="myCenter"/>
7
        </destinations>
8
        <subscribes>
9
            <subscribe subDestination="test">
10
                <implclass>com.ai.ipu.example.rabbitmq.RabbitMQCustomerExample</implclass>
11
            </subscribe>
12
        </subscribes>
13
        <centers>
14
            <center name="myCenter" containClusters="rabbitmq-cluster"/>
15
        </centers>
16
        <clusters>
17
            <cluster name="rabbitmq-cluster" type="RabbitMQ">
18
                <url user="admin" password="admin">47.105.160.21</url>
19
            </cluster>
20
        </clusters>
21
    </centerCfg>
22
</msgframeCfg>

+ 86 - 0
ipu-rocketmq-example/pom.xml

@ -0,0 +1,86 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
    <modelVersion>4.0.0</modelVersion>
6
7
    <groupId>com.ai.ipu</groupId>
8
    <artifactId>ipu-rocketmq-example</artifactId>
9
    <version>1.0-SNAPSHOT</version>
10
11
    <properties>
12
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13
        <ipu>3.1-SNAPSHOT</ipu>
14
        <jdk>1.8</jdk>
15
    </properties>
16
17
    <dependencies>
18
        <dependency>
19
            <groupId>com.ai.aif.msgframe</groupId>
20
            <artifactId>msgframe-common</artifactId>
21
            <version>1.9.2</version>
22
        </dependency>
23
        <dependency>
24
            <groupId>com.ai.aif.msgframe</groupId>
25
            <artifactId>msgframe-client</artifactId>
26
            <version>1.9.2</version>
27
        </dependency>
28
        <dependency>
29
            <groupId>com.ai.aif.msgframe</groupId>
30
            <artifactId>msgframe-server</artifactId>
31
            <version>1.9.2</version>
32
        </dependency>
33
        <dependency>
34
            <groupId>com.ai.aif.msgframe</groupId>
35
            <artifactId>xmlmsgframe</artifactId>
36
            <version>2.6.4</version>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.apache.xmlbeans</groupId>
40
            <artifactId>xmlbeans</artifactId>
41
            <version>2.6.0</version>
42
        </dependency>
43
        <dependency>
44
            <groupId>com.rabbitmq</groupId>
45
            <artifactId>amqp-client</artifactId>
46
            <version>3.6.5</version>
47
        </dependency>
48
        <dependency>
49
            <groupId>com.alibaba</groupId>
50
            <artifactId>fastjson</artifactId>
51
            <version>1.1.46</version>
52
        </dependency>
53
        <dependency>
54
            <groupId>org.hamcrest</groupId>
55
            <artifactId>hamcrest-core</artifactId>
56
            <version>1.3</version>
57
        </dependency>
58
        <dependency>
59
            <groupId>javax.jms</groupId>
60
            <artifactId>jms</artifactId>
61
            <version>1.1</version>
62
        </dependency>
63
        <dependency>
64
            <groupId>org.apache.kafka</groupId>
65
            <artifactId>kafka-clients</artifactId>
66
            <version>0.10.2.0</version>
67
        </dependency>
68
        <dependency>
69
            <groupId>log4j</groupId>
70
            <artifactId>log4j</artifactId>
71
            <version>1.2.12</version>
72
        </dependency>
73
        <dependency>
74
            <groupId>com.alibaba.rocketmq</groupId>
75
            <artifactId>rocketmq-client</artifactId>
76
            <version>3.5.9</version>
77
        </dependency>
78
        <dependency>
79
            <groupId>junit</groupId>
80
            <artifactId>junit</artifactId>
81
            <version>4.12</version>
82
            <scope>compile</scope>
83
        </dependency>
84
    </dependencies>
85
86
</project>

+ 15 - 0
ipu-rocketmq-example/src/main/java/com/ai/ipu/example/rocketmq/RocketMQCustomer.java

@ -0,0 +1,15 @@
1
package com.ai.ipu.example.rocketmq;
2
3
import com.ai.aif.msgframe.consumer.MfServiceStartup;
4
5
/**
6
 * @author liutong3
7
 * @team IPU
8
 * @date 2019/6/10 14:13
9
 * @desc 启动RocketMQ消费者
10
 */
11
public class RocketMQCustomer {
12
    public static void main(String[] args){
13
        MfServiceStartup.main();
14
    }
15
}

+ 23 - 0
ipu-rocketmq-example/src/main/java/com/ai/ipu/example/rocketmq/RocketMQCustomerExample.java

@ -0,0 +1,23 @@
1
package com.ai.ipu.example.rocketmq;
2
3
import com.ai.aif.msgframe.common.IConsumerProcessor;
4
import com.ai.aif.msgframe.common.exception.ConsumerException;
5
import com.ai.aif.msgframe.common.message.MsgFMessage;
6
import com.ai.aif.msgframe.common.message.MsgFTextMessage;
7
8
/**
9
 * @author liutong3
10
 * @team IPU
11
 * @date 2019/6/10 14:15
12
 * @desc RocketMQ消费者
13
 */
14
public class RocketMQCustomerExample implements IConsumerProcessor {
15
    @SuppressWarnings("rawtypes")
16
    public Object process(MsgFMessage message) throws ConsumerException {
17
        if (message instanceof MsgFTextMessage) {
18
            System.out.println("{topic:" + message.getTopic() + ",value:" + ((MsgFTextMessage) message).getText() + "}");
19
        }
20
        return true;
21
    }
22
}
23

+ 114 - 0
ipu-rocketmq-example/src/main/java/com/ai/ipu/example/rocketmq/RocketMQProducerExample.java

@ -0,0 +1,114 @@
1
package com.ai.ipu.example.rocketmq;
2
3
import com.ai.aif.msgframe.MfProducerClient;
4
import com.ai.aif.msgframe.common.CompletionListener;
5
import com.ai.aif.msgframe.common.message.MsgFMessage;
6
import com.ai.aif.msgframe.common.message.MsgFTextMessage;
7
import org.apache.log4j.Logger;
8
import org.junit.Test;
9
10
import java.util.Date;
11
12
/**
13
 * @author liutong3
14
 * @team IPU
15
 * @date 2019/6/10 14:16
16
 * @desc RocketMQ生产者
17
 */
18
public class RocketMQProducerExample {
19
    private static final Logger LOG = Logger.getLogger(RocketMQProducerExample.class);
20
    private final String TOPIC = "test";
21
    private final String MESSAGE = "test";
22
    private final String ORDERID = "1000";
23
24
    @Test
25
    public void testSendMessage() {
26
        String message = getMessage();
27
        sendMessage(TOPIC, message);
28
    }
29
30
    @Test
31
    public void testSendAsyncMessage() {
32
        String message = getMessage();
33
        sendAsyncMessage(TOPIC, message);
34
    }
35
36
    @Test
37
    public void testSendOrderMessage() {
38
        String message = getMessage();
39
        sendOrderMessage(TOPIC, message, ORDERID);
40
    }
41
42
    @Test
43
    public void testSendOneWay() {
44
        String message = getMessage();
45
        sendOneWay(TOPIC, message);
46
    }
47
48
    private String getMessage() {
49
        return MESSAGE + "_" + new Date().getTime();
50
    }
51
52
    private void sendMessage(String topic, String text) {
53
        try {
54
            MfProducerClient client = new MfProducerClient();
55
            MsgFTextMessage message = new MsgFTextMessage();
56
            message.setText(text);
57
            client.send(topic, message);
58
            LOG.debug("Sent:" + message);
59
            Thread.currentThread().sleep(1000);
60
        } catch (Exception e) {
61
            LOG.debug(e);
62
            throw new RuntimeException(e);
63
        }
64
    }
65
66
    private void sendAsyncMessage(String topic, final String text) {
67
        try {
68
            MfProducerClient client = new MfProducerClient();
69
            final MsgFTextMessage message = new MsgFTextMessage();
70
            message.setText(text);
71
            client.asyncSend(topic, message, new CompletionListener() {
72
                public void onCompletion(MsgFMessage msgFMessage) {
73
                    LOG.debug("Sent Success:" + msgFMessage.getMsgId() + "-" + text);
74
                }
75
76
                public void onException(MsgFMessage msgFMessage, Exception e) {
77
                    LOG.debug("Sent Error:" + msgFMessage.getMsgId() + "-" + text);
78
                }
79
            });
80
            Thread.currentThread().sleep(1000);
81
        } catch (Exception e) {
82
            LOG.debug(e);
83
            throw new RuntimeException(e);
84
        }
85
    }
86
87
    private void sendOrderMessage(String topic, final String text, String orderId) {
88
        try {
89
            MfProducerClient client = new MfProducerClient();
90
            final MsgFTextMessage message = new MsgFTextMessage();
91
            message.setText(text);
92
            client.sendOrderMsg(topic, message, orderId);
93
            LOG.debug("Sent:" + message);
94
            Thread.currentThread().sleep(1000);
95
        } catch (Exception e) {
96
            LOG.debug(e);
97
            throw new RuntimeException(e);
98
        }
99
    }
100
101
    private void sendOneWay(String topic, final String text) {
102
        try {
103
            MfProducerClient client = new MfProducerClient();
104
            final MsgFTextMessage message = new MsgFTextMessage();
105
            message.setText(text);
106
            client.sendOneway(topic, message);
107
            LOG.debug("Sent:" + message);
108
            Thread.currentThread().sleep(1000);
109
        } catch (Exception e) {
110
            LOG.debug(e);
111
            throw new RuntimeException(e);
112
        }
113
    }
114
}

+ 8 - 0
ipu-rocketmq-example/src/main/resources/log4j.properties

@ -0,0 +1,8 @@
1
log4j.rootLogger=error, console
2
log4j.logger.org.apache.zookeeper=error
3
log4j.logger.com.ai.ipu.example=debug
4
5
log4j.appender.console=org.apache.log4j.ConsoleAppender
6
log4j.appender.console.target=System.out
7
log4j.appender.console.layout=org.apache.log4j.PatternLayout
8
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %5p [%t] (%F:%L) - %m%n

+ 22 - 0
ipu-rocketmq-example/src/main/resources/msgframe-config.xml

@ -0,0 +1,22 @@
1
<?xml version="1.0" encoding="UTF-8"?>
2
<msgframeCfg xmlns="http://www.asiainfo.com/msgframe">
3
    <centerCfg>
4
        <name>ipu-rocketmq-example</name>
5
        <destinations>
6
            <queue name="test" belong="myCenter"/>
7
        </destinations>
8
        <subscribes>
9
            <subscribe subDestination="test">
10
                <implclass>com.ai.ipu.example.rocketmq.RocketMQCustomerExample</implclass>
11
            </subscribe>
12
        </subscribes>
13
        <centers>
14
            <center name="myCenter" containClusters="rocketmq-cluster"/>
15
        </centers>
16
        <clusters>
17
            <cluster name="rocketmq-cluster" type="RocketMQ">
18
                <url>47.105.160.21:9876</url>
19
            </cluster>
20
        </clusters>
21
    </centerCfg>
22
</msgframeCfg>