-
Notifications
You must be signed in to change notification settings - Fork 63
/
ProduceConsume.java
executable file
·73 lines (57 loc) · 2.13 KB
/
ProduceConsume.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.messagebus.client.api;
import com.messagebus.client.IMessageReceiveListener;
import com.messagebus.client.core.BaseTestCase;
import com.messagebus.client.message.model.Message;
import com.messagebus.client.message.model.MessageFactory;
import com.messagebus.common.Constants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Created by yanghua on 3/20/15.
*/
public class ProduceConsume extends BaseTestCase {
private static final Log logger = LogFactory.getLog(ProduceConsume.class);
private String consumeSecret = "kjhasdfhlkuqjhgaebjhasgdfabfak";
@Override
public void setUp() throws Exception {
super.setUp();
}
@Override
public void tearDown() throws Exception {
super.tearDown();
}
private void commonProduce() {
String secret = "kljasdoifqoikjhhhqwhebasdfasdf";
String token = "hlkasjdhfkqlwhlfalksjdhgssssas";
Message msg = MessageFactory.createMessage();
msg.setContentType("text/plain");
msg.setContentEncoding("utf-8");
msg.setContent("test".getBytes());
client.produce(secret, "erpDemoConsume", msg, token);
}
public void testSimpleProduceConsume() throws Exception {
commonProduce();
List<Message> msgs = client.consume(consumeSecret, 1);
assertNotNull(msgs);
assertEquals(1, msgs.size());
Message result = msgs.get(0);
assertNotNull(result);
assertNotNull(result.getContent());
assertEquals("test", new String(result.getContent()));
for (Message item : msgs) {
logger.info(item.getMessageId());
}
}
public void testProduceAndConsumeWithPushStyle() {
commonProduce();
client.consume(consumeSecret, 3, TimeUnit.SECONDS, new IMessageReceiveListener() {
@Override
public void onMessage(Message message) {
assertNotNull(message);
assertEquals("test", new String(message.getContent(), Constants.CHARSET_OF_UTF8));
}
});
}
}