Search in sources :

Example 1 with LocalTransactionExecuter

use of com.yanghui.elephant.client.producer.LocalTransactionExecuter in project elephant by yanghuijava.

the class TransactionProducer method main.

public static void main(String[] args) throws MQClientException {
    TransactionMQProducer producer = new TransactionMQProducer("transaction-test");
    producer.setRegisterCenter("120.77.152.143:2181");
    producer.setTransactionCheckListener(new TransactionCheckListenerImpl());
    producer.start();
    LocalTransactionExecuter excuter = new LocalTransactionExecuterImpl();
    /**
     * 目前只支持activemq:
     * 发送queue,message的destination值加上前缀:queue://
     * 发送topic,message的destination值加上前缀:topic://
     */
    for (int i = 0; i < 1; i++) {
        Message msg = new Message("queue://yanghui.queue.test1", ("我是事务消息" + i).getBytes());
        TransactionSendResult transactionSendResult = producer.sendMessageTransaction(msg, excuter, null);
        System.out.println(transactionSendResult);
    }
// producer.shutdown();
}
Also used : Message(com.yanghui.elephant.common.message.Message) LocalTransactionExecuter(com.yanghui.elephant.client.producer.LocalTransactionExecuter) TransactionSendResult(com.yanghui.elephant.client.producer.TransactionSendResult) TransactionMQProducer(com.yanghui.elephant.client.producer.TransactionMQProducer)

Example 2 with LocalTransactionExecuter

use of com.yanghui.elephant.client.producer.LocalTransactionExecuter in project elephant by yanghuijava.

the class TransactionProducer1 method main.

public static void main(String[] args) throws MQClientException {
    TransactionMQProducer producer1 = new TransactionMQProducer("transaction-test1");
    producer1.setRegisterCenter("172.16.21.12:2181");
    producer1.setTransactionCheckListener(new TransactionCheckListenerImpl());
    producer1.start();
    TransactionMQProducer producer2 = new TransactionMQProducer("transaction-test2");
    producer2.setRegisterCenter("172.16.21.12:2181");
    producer2.setTransactionCheckListener(new TransactionCheckListenerImpl2());
    producer2.start();
    LocalTransactionExecuter excuter = new LocalTransactionExecuterImpl();
    Message msg1 = new Message("topic://VirtualTopic.Test", ("我是事务消息1").getBytes());
    TransactionSendResult transactionSendResult1 = producer1.sendMessageTransaction(msg1, excuter, null);
    System.out.println("transactionSendResult1=" + transactionSendResult1);
    Message msg2 = new Message("topic://VirtualTopic.Test", ("我是事务消息2").getBytes());
    TransactionSendResult transactionSendResult2 = producer2.sendMessageTransaction(msg2, excuter, null);
    System.out.println("transactionSendResult2=" + transactionSendResult2);
}
Also used : Message(com.yanghui.elephant.common.message.Message) LocalTransactionExecuter(com.yanghui.elephant.client.producer.LocalTransactionExecuter) TransactionSendResult(com.yanghui.elephant.client.producer.TransactionSendResult) TransactionMQProducer(com.yanghui.elephant.client.producer.TransactionMQProducer)

Aggregations

LocalTransactionExecuter (com.yanghui.elephant.client.producer.LocalTransactionExecuter)2 TransactionMQProducer (com.yanghui.elephant.client.producer.TransactionMQProducer)2 TransactionSendResult (com.yanghui.elephant.client.producer.TransactionSendResult)2 Message (com.yanghui.elephant.common.message.Message)2