Java Code Examples for org.apache.rocketmq.client.producer.LocalTransactionState#COMMIT_MESSAGE
The following examples show how to use
org.apache.rocketmq.client.producer.LocalTransactionState#COMMIT_MESSAGE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransactionListenerImpl.java From java-tutorial with MIT License | 6 votes |
/** * 可以根据由MQ回传的key去数据库查询,这条数据到底是成功了还是失败了。 * * @param messageExt * @return */ @Override public LocalTransactionState checkLocalTransaction(MessageExt messageExt) { Integer status = localTrans.get(messageExt.getTransactionId()); if (null != status) { switch (status) { case 0: return LocalTransactionState.UNKNOW; case 1: return LocalTransactionState.COMMIT_MESSAGE; default: return LocalTransactionState.ROLLBACK_MESSAGE; } } return LocalTransactionState.COMMIT_MESSAGE; }
Example 2
Source File: TransactionalMsgIT.java From rocketmq with Apache License 2.0 | 6 votes |
static Pair<Boolean, LocalTransactionState> getTransactionHandle(int msgIndex) { switch (msgIndex % 5) { case 0: //commit immediately return new Pair<>(true, LocalTransactionState.COMMIT_MESSAGE); case 1: //rollback immediately return new Pair<>(true, LocalTransactionState.ROLLBACK_MESSAGE); case 2: //commit in check return new Pair<>(false, LocalTransactionState.COMMIT_MESSAGE); case 3: //rollback in check return new Pair<>(false, LocalTransactionState.ROLLBACK_MESSAGE); case 4: default: return new Pair<>(false, LocalTransactionState.UNKNOW); } }
Example 3
Source File: LocalTranListenerImpl.java From order-charge-notify with Apache License 2.0 | 6 votes |
/** * 本地事务回查: 回查依据是否存在扣款流水 * @param msg * @return */ @Override public LocalTransactionState checkLocalTransaction(MessageExt msg) { // 本地事务回查,查询扣款流水 String message = new String(msg.getBody()); String msgId = msg.getMsgId(); LOGGER.info("[扣款本地事务回查]-接收到消息,msgId={},message={}", msgId, message); WalletPaymentProtocol payProtocol = new WalletPaymentProtocol(); payProtocol.decode(message); // 获取订单号 String orderId = payProtocol.getOrderId(); ChargeRecordEntity chargeRecordEntity = walletService.queryChargeRecordByOrderId(orderId); if (chargeRecordEntity == null) { LOGGER.info("[扣款本地事务回查]-本地不存在扣款流水,消息回滚,msgId={}", msgId); return LocalTransactionState.ROLLBACK_MESSAGE; } LOGGER.info("[扣款本地事务回查]-本地存在扣款流水,消息提交,msgId={}", msgId); return LocalTransactionState.COMMIT_MESSAGE; }
Example 4
Source File: TransactionListenerImpl.java From rocketmq-read with Apache License 2.0 | 6 votes |
@Override public LocalTransactionState checkLocalTransaction(MessageExt msg) { Integer status = localTrans.get(msg.getTransactionId()); if (null != status) { switch (status) { case 0: return LocalTransactionState.UNKNOW; case 1: return LocalTransactionState.COMMIT_MESSAGE; case 2: return LocalTransactionState.ROLLBACK_MESSAGE; default: return LocalTransactionState.COMMIT_MESSAGE; } } return LocalTransactionState.COMMIT_MESSAGE; }
Example 5
Source File: TransactionCheckListenerImpl.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { System.out.printf("server checking TrMsg " + msg.toString() + "%n"); int value = transactionIndex.getAndIncrement(); if ((value % 6) == 0) { throw new RuntimeException("Could not find db"); } else if ((value % 5) == 0) { return LocalTransactionState.ROLLBACK_MESSAGE; } else if ((value % 4) == 0) { return LocalTransactionState.COMMIT_MESSAGE; } return LocalTransactionState.UNKNOW; }
Example 6
Source File: TransactionCheckListenerImpl.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { System.out.printf("server checking TrMsg " + msg.toString() + "%n"); int value = transactionIndex.getAndIncrement(); if ((value % 6) == 0) { throw new RuntimeException("Could not find db"); } else if ((value % 5) == 0) { return LocalTransactionState.ROLLBACK_MESSAGE; } else if ((value % 4) == 0) { return LocalTransactionState.COMMIT_MESSAGE; } return LocalTransactionState.UNKNOW; }
Example 7
Source File: TransactionProducer.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet(); if (ischeckffalse) { return LocalTransactionState.ROLLBACK_MESSAGE; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 8
Source File: RMQTransactionalProducer.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public ResultWrapper send(Object msg, Object arg) { boolean commitMsg = ((Pair<Boolean, LocalTransactionState>) arg).getObject2() == LocalTransactionState.COMMIT_MESSAGE; org.apache.rocketmq.client.producer.SendResult metaqResult = null; Message message = (Message) msg; try { long start = System.currentTimeMillis(); metaqResult = producer.sendMessageInTransaction(message, arg); this.msgRTs.addData(System.currentTimeMillis() - start); if (isDebug) { logger.info(metaqResult); } sendResult.setMsgId(metaqResult.getMsgId()); sendResult.setSendResult(true); sendResult.setBrokerIp(metaqResult.getMessageQueue().getBrokerName()); if (commitMsg) { msgBodys.addData(new String(message.getBody())); } originMsgs.addData(msg); originMsgIndex.put(new String(message.getBody()), metaqResult); } catch (MQClientException e) { if (isDebug) { e.printStackTrace(); } sendResult.setSendResult(false); sendResult.setSendException(e); errorMsgs.addData(msg); } return sendResult; }
Example 9
Source File: TransactionCheckListenerImpl.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { System.out.printf("server checking TrMsg %s%n", msg); int value = transactionIndex.getAndIncrement(); if ((value % 6) == 0) { throw new RuntimeException("Could not find db"); } else if ((value % 5) == 0) { return LocalTransactionState.ROLLBACK_MESSAGE; } else if ((value % 4) == 0) { return LocalTransactionState.COMMIT_MESSAGE; } return LocalTransactionState.UNKNOW; }
Example 10
Source File: TransactionProducer.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet(); if (ischeckffalse) { return LocalTransactionState.ROLLBACK_MESSAGE; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 11
Source File: TransactionProducer.java From rocketmq-read with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) { if (ischeck) { return LocalTransactionState.UNKNOW; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 12
Source File: TransactionProducer.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet(); if (ischeckffalse) { return LocalTransactionState.ROLLBACK_MESSAGE; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 13
Source File: TransactionListenerImpl.java From gpmall with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransaction(MessageExt msg) { Integer status = localTrans.get(msg.getTransactionId()); if (null != status) { switch (status) { case 0: return LocalTransactionState.UNKNOW; case 1: return LocalTransactionState.COMMIT_MESSAGE; case 2: return LocalTransactionState.ROLLBACK_MESSAGE; } } return LocalTransactionState.COMMIT_MESSAGE; }
Example 14
Source File: TransactionProducer.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet(); if (ischeckffalse) { return LocalTransactionState.ROLLBACK_MESSAGE; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 15
Source File: TransactionProducer.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState executeLocalTransaction(final Message msg, final Object arg) { if (isCheckLocal) { return LocalTransactionState.UNKNOW; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 16
Source File: TransactionProducer.java From rocketmq-4.3.0 with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransaction(MessageExt msg) { statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet(); if (isCheckFalse) { return LocalTransactionState.ROLLBACK_MESSAGE; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 17
Source File: TransactionListenerImpl.java From blog with BSD 2-Clause "Simplified" License | 5 votes |
@Override public LocalTransactionState executeLocalTransaction(Message msg, Object arg) { System.out.println("executeLocalTransaction"); int value = transactionIndex.getAndIncrement(); int status = value % 3; localTrans.put(msg.getTransactionId(), status); return LocalTransactionState.COMMIT_MESSAGE; }
Example 18
Source File: TransactionCheckListenerImpl.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState checkLocalTransactionState(MessageExt msg) { try { String val = new String(msg.getBody(), "UTF-8"); System.out.printf("server checking TrMsg " + val + "%n"); if (Integer.parseInt(val) < 0) { return LocalTransactionState.UNKNOW; } if (statsMap.get(Integer.parseInt(val)) != null && statsMap.get(Integer.parseInt(val))) { return LocalTransactionState.COMMIT_MESSAGE; } else { System.out.printf("server checking TrMsg " + val + ",ROLLBACK"); return LocalTransactionState.ROLLBACK_MESSAGE; } } catch (Exception e) { e.printStackTrace(); return LocalTransactionState.ROLLBACK_MESSAGE; } // int value = transactionIndex.getAndIncrement(); // if ((value % 6) == 0) { // throw new RuntimeException("Could not find db"); // } else if ((value % 5) == 0) { // return LocalTransactionState.ROLLBACK_MESSAGE; // } else if ((value % 4) == 0) { // return LocalTransactionState.COMMIT_MESSAGE; // } //return LocalTransactionState.COMMIT_MESSAGE; }
Example 19
Source File: TransactionProducer.java From DDMQ with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) { if (ischeck) { return LocalTransactionState.UNKNOW; } return LocalTransactionState.COMMIT_MESSAGE; }
Example 20
Source File: TransactionProducer.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) { if (ischeck) { return LocalTransactionState.UNKNOW; } return LocalTransactionState.COMMIT_MESSAGE; }