use of com.yanghui.elephant.client.producer.TransactionMQProducer 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();
}
use of com.yanghui.elephant.client.producer.TransactionMQProducer 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);
}
use of com.yanghui.elephant.client.producer.TransactionMQProducer in project elephant by yanghuijava.
the class DefaultMQProducerImpl method checkTransactionState.
@Override
public void checkTransactionState(final String address, final String producerGroupe, final Message msg) {
Runnable run = new Runnable() {
@Override
public void run() {
try {
TransactionMQProducer producer = (TransactionMQProducer) defaultMQProducer;
LocalTransactionState localState = producer.getTransactionCheckListener().checkLocalTransactionState(msg);
CheckTransactionStateResponseHeader header = new CheckTransactionStateResponseHeader();
header.setCommitOrRollback(localState.name());
header.setMessageId(msg.getMessageId());
header.setProducerGroup(defaultMQProducer.getProducerGroup());
RemotingCommand request = RemotingCommand.buildRequestCmd(header, RequestCode.CHECK_TRANSACTION_RESPONSE);
mqProducerFactory.getRemotingClient().invokeOneway(address, request, 0);
} catch (Exception e) {
log.error("check transaction state error:{}", e);
}
}
};
this.checkExecutor.submit(run);
}
use of com.yanghui.elephant.client.producer.TransactionMQProducer in project elephant by yanghuijava.
the class DefaultMQProducerImpl method initTransaction.
public void initTransaction() {
TransactionMQProducer producer = (TransactionMQProducer) this.defaultMQProducer;
this.checkRequestQueue = new LinkedBlockingQueue<Runnable>(producer.getCheckRequestHoldMax());
this.checkExecutor = new ThreadPoolExecutor(producer.getCheckThreadPoolMinSize(), producer.getCheckThreadPoolMaxSize(), 1000 * 60, TimeUnit.MILLISECONDS, this.checkRequestQueue, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "transactioncheckExecutorThread");
}
});
this.mqProducerFactory.registerDefaultRequestProcessor();
}
Aggregations