public class TransactionProducer {
public static void main(final String[] args) throws Exception {
// New session factory,ǿ�ҽ���ʹ�õ���
final MessageSessionFactory sessionFactory = new MetaMessageSessionFactory(initMetaConfig());
// create producer,ǿ�ҽ���ʹ�õ���
final MessageProducer producer = sessionFactory.createProducer();
// publish topic
final String topic = "meta-test";
producer.publish(topic);
// ��������ʱΪ10��
producer.setTransactionTimeout(10);
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while ((line = readLine(reader)) != null) {
try {
// ��ʼ����
producer.beginTransaction();
// �������ڷ���������Ϣ
if (!producer.sendMessage(new Message(topic, line.getBytes())).isSuccess()) {
// ����ʧ�ܣ������ع�
producer.rollback();
continue;
}
if (!producer.sendMessage(new Message(topic, line.getBytes())).isSuccess()) {
producer.rollback();
continue;
}
// �ύ
producer.commit();
}
catch (final Exception e) {
producer.rollback();
}
}
}