um lines-num-old"> 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>

ipu/android-share - Nuosi Git Service

55 Commits (95ca34ee422ba6674f371f95ca338867d17cde13)

Author SHA1 Message Date
  huangbo 22bd19543c 初始化 10 years ago
  huangbo 307cee8c71 1 10 years ago
  huangbo 8aa85d121f 初始化 10 years ago
  huangbo 1f191c2a19 初始化 10 years ago
  huangbo c6fe54d25f Init commit 10 years ago