@Test
public void sendConsume() throws Exception {
this.createProducer();
this.producer.publish(this.topic);
final ConsumerConfig consumerConfig = new ConsumerConfig("group1");
consumerConfig.setMaxFetchRetries(5);
this.consumer = this.sessionFactory.createConsumer(consumerConfig);
final AtomicInteger i = new AtomicInteger(0);
try {
int count = 2;
this.sendMessage(count, "hello", this.topic);
this.consumer.subscribe(this.topic, 1024 * 1024, new MessageListener() {
public void recieveMessages(final Message messages) {
ComsumeFailAndRecoverTest.this.queue.add(messages);
// ��һ�ν��յ����쳣,retry 5+1�ξ����쳣֮����Ϣ�Ž���recover,recoverһ�δ���ɹ�
// ������������Ϣ8��
// ���ϵڶ�����Ϣ,������һ����9����Ϣ
if (Arrays.equals(messages.getData(), "hello0".getBytes())
&& i.get() <= consumerConfig.getMaxFetchRetries() + 1) {
i.incrementAndGet();
throw new RuntimeException("don't worry,just for test");
}
}
public Executor getExecutor() {
return null;
}
}).completeSubscribe();
while (this.queue.size() < count + 2 + consumerConfig.getMaxFetchRetries()) {
Thread.sleep(1000);
System.out.println("�ȴ�������Ϣ" + (count + 2 + consumerConfig.getMaxFetchRetries()) + "����Ŀǰ���յ�"
+ this.queue.size() + "��");
}
int j = 0;
for (Message msg : this.queue) {