org.apache.rocketmq.client.producer.LocalTransactionState Java Examples

The following examples show how to use org.apache.rocketmq.client.producer.LocalTransactionState. 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 vote down vote up
/**
 * 可以根据由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 vote down vote up
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: TransactionListenerImpl.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: ChargeOrderTranListenerImpl.java    From order-charge-notify with Apache License 2.0 6 votes vote down vote up
/**
 * 根据订单号进行回查
 * @param msg
 * @return
 */
@Override
public LocalTransactionState checkLocalTransaction(MessageExt msg) {
    String message = new String(msg.getBody());
    String msgId = msg.getMsgId();
    int reconsumeTimes = msg.getReconsumeTimes();
    LOGGER.info("订单入库本地事务回查--接收到消息, msgId={},message={},reconsumeTimes={}", msgId, message, reconsumeTimes);
    // 消息解码
    WalletPaymentProtocol walletPaymentProtocol = new WalletPaymentProtocol();
    walletPaymentProtocol.decode(message);
    String orderId = walletPaymentProtocol.getOrderId();
    // 订单查询
    OrderInfoDO orderInfoDO = new OrderInfoDO().setOrderId(orderId);
    OrderInfoDobj orderInfoDobj = orderChargeService.queryOrderInfo(orderInfoDO);
    if (orderInfoDobj == null) {
        LOGGER.info("订单入库本地事务回查--本地不存在订单,[消息回滚],orderId={},msgId={}", orderId, msgId);
        return LocalTransactionState.ROLLBACK_MESSAGE;
    }
    LOGGER.info("订单入库本地事务回查--本地存在订单信息,orderInfoDobj={},msgId={},[消息提交]", orderInfoDobj, msgId);
    return LocalTransactionState.COMMIT_MESSAGE;
}
 
Example #5
Source File: ChargeOrderTranListenerImpl.java    From order-charge-notify with Apache License 2.0 6 votes vote down vote up
/**
 * 执行本地订单入库操作
 * @param msg
 * @param arg
 * @return
 */
@Override
public LocalTransactionState executeLocalTransaction(Message msg, Object arg) {
    // 消息解码
    String message = new String(msg.getBody());
    WalletPaymentProtocol walletPaymentProtocol = new WalletPaymentProtocol();
    walletPaymentProtocol.decode(message);
    LOGGER.info("订单入库实体WalletPaymentProtocol={}", walletPaymentProtocol.toString());
    // 组装下单实体
    OrderInfoDO orderInfoDO = new OrderInfoDO();
    BeanUtils.copyProperties(walletPaymentProtocol, orderInfoDO);
    String orderId = orderInfoDO.getOrderId();
    // 执行下单操作
    try {
        if (!orderChargeService.insertOrder(orderInfoDO)) {
            LOGGER.error("订单入库失败,事务消息回滚,LocalTransactionState={},orderId={}", LocalTransactionState.ROLLBACK_MESSAGE, orderId);
            return LocalTransactionState.ROLLBACK_MESSAGE;
        }
    } catch (Exception e) {
        LOGGER.error("订单入库异常,等待回查发起,orderId={},e={}", orderId, LogExceptionWapper.getStackTrace(e));
        return LocalTransactionState.UNKNOW;
    }
    LOGGER.info("订单入库成功,orderId={}", orderId);
    return LocalTransactionState.COMMIT_MESSAGE;
}
 
Example #6
Source File: TransactionListenerImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: LocalTranListenerImpl.java    From order-charge-notify with Apache License 2.0 6 votes vote down vote up
/**
 * 本地事务回查: 回查依据是否存在扣款流水
 * @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 #8
Source File: TransactionListenerImpl.java    From blog with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public LocalTransactionState checkLocalTransaction(MessageExt msg) {
	Integer status = localTrans.get(msg.getTransactionId());
	System.out.println("checkLocalTransaction:status = " + status);
	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 #9
Source File: TransactionExecuterImpl.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) {
    Integer cnt = (Integer) arg;
    if(cnt%5==0){
        //return LocalTransactionState.ROLLBACK_MESSAGE;
    }
    try {
        Thread.sleep(new Random().nextInt(200));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return LocalTransactionState.COMMIT_MESSAGE;
   //return LocalTransactionState.UNKNOW;
}
 
Example #10
Source File: TransactionalMsgIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransaction(Message msg, Object arg) {
    Pair<Boolean, LocalTransactionState> transactionHandle = (Pair<Boolean,LocalTransactionState>) arg;
    if (transactionHandle.getObject1()) {
        return transactionHandle.getObject2();
    } else {
        checkStatus.put(msg.getTransactionId(), transactionHandle.getObject2());
        return LocalTransactionState.UNKNOW;
    }
}
 
Example #11
Source File: RMQTransactionalProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: DefaultMQProducerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void endTransaction(
    final SendResult sendResult,
    final LocalTransactionState localTransactionState,
    final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException {
    final MessageId id;
    if (sendResult.getOffsetMsgId() != null) {
        id = MessageDecoder.decodeMessageId(sendResult.getOffsetMsgId());
    } else {
        id = MessageDecoder.decodeMessageId(sendResult.getMsgId());
    }
    String transactionId = sendResult.getTransactionId();
    final String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(sendResult.getMessageQueue().getBrokerName());
    EndTransactionRequestHeader requestHeader = new EndTransactionRequestHeader();
    requestHeader.setTransactionId(transactionId);
    requestHeader.setCommitLogOffset(id.getOffset());
    switch (localTransactionState) {
        case COMMIT_MESSAGE:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_COMMIT_TYPE);
            break;
        case ROLLBACK_MESSAGE:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_ROLLBACK_TYPE);
            break;
        case UNKNOW:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_NOT_TYPE);
            break;
        default:
            break;
    }

    requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup());
    requestHeader.setTranStateTableOffset(sendResult.getQueueOffset());
    requestHeader.setMsgId(sendResult.getMsgId());
    String remark = localException != null ? ("executeLocalTransactionBranch exception: " + localException.toString()) : null;
    this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, requestHeader, remark,
        this.defaultMQProducer.getSendMsgTimeout());
}
 
Example #13
Source File: TransactionProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private MsgMeta parseFromMsg(Message msg) {
    byte[] bs = msg.getBody();
    ByteBuffer buf = ByteBuffer.wrap(bs);
    MsgMeta msgMeta = new MsgMeta();
    msgMeta.batchId = buf.getLong();
    msgMeta.msgId = buf.getLong();
    msgMeta.sendResult = LocalTransactionState.values()[buf.get()];
    msgMeta.checkResult = new ArrayList<>();
    for (int i = 0; i < TransactionProducer.MAX_CHECK_RESULT_IN_MSG; i++) {
        msgMeta.checkResult.add(LocalTransactionState.values()[buf.get()]);
    }
    return msgMeta;
}
 
Example #14
Source File: TransactionListenerImpl.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransaction(Message msg, Object arg) {
    int value = transactionIndex.getAndIncrement();
    int status = value % 3;
    localTrans.put(msg.getTransactionId(), status);
    return LocalTransactionState.UNKNOW;
}
 
Example #15
Source File: TransactionProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState checkLocalTransactionState(MessageExt msg) {
    statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet();
    if (ischeckffalse) {

        return LocalTransactionState.ROLLBACK_MESSAGE;
    }

    return LocalTransactionState.COMMIT_MESSAGE;
}
 
Example #16
Source File: DefaultMQProducerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public void endTransaction(//
    final SendResult sendResult, //
    final LocalTransactionState localTransactionState, //
    final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException {
    final MessageId id;
    if (sendResult.getOffsetMsgId() != null) {
        id = MessageDecoder.decodeMessageId(sendResult.getOffsetMsgId());
    } else {
        id = MessageDecoder.decodeMessageId(sendResult.getMsgId());
    }
    String transactionId = sendResult.getTransactionId();
    final String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(sendResult.getMessageQueue().getBrokerName());
    EndTransactionRequestHeader requestHeader = new EndTransactionRequestHeader();
    requestHeader.setTransactionId(transactionId);
    requestHeader.setCommitLogOffset(id.getOffset());
    switch (localTransactionState) {
        case COMMIT_MESSAGE:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_COMMIT_TYPE);
            break;
        case ROLLBACK_MESSAGE:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_ROLLBACK_TYPE);
            break;
        case UNKNOW:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_NOT_TYPE);
            break;
        default:
            break;
    }

    requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup());
    requestHeader.setTranStateTableOffset(sendResult.getQueueOffset());
    requestHeader.setMsgId(sendResult.getMsgId());
    String remark = localException != null ? ("executeLocalTransactionBranch exception: " + localException.toString()) : null;
    this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, requestHeader, remark,
        this.defaultMQProducer.getSendMsgTimeout());
}
 
Example #17
Source File: TransactionProducer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) {
    if (ischeck) {
        return LocalTransactionState.UNKNOW;
    }
    return LocalTransactionState.COMMIT_MESSAGE;
}
 
Example #18
Source File: TransactionCheckListenerImpl.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
@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: TransactionListenerImpl.java    From gpmall with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransaction(Message msg, Object arg) {
	int value = transactionIndex.getAndIncrement();
	int status = value % 3;
	localTrans.put(msg.getTransactionId(), status);
	return LocalTransactionState.UNKNOW;
}
 
Example #20
Source File: TransactionalMsgIT.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState checkLocalTransaction(MessageExt msg) {
    LocalTransactionState state = checkStatus.get(msg.getTransactionId());
    if (state == null) {
        return LocalTransactionState.UNKNOW;
    } else {
        return state;
    }
}
 
Example #21
Source File: TransactionProducer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
private static Message buildMessage(TxSendConfig config) {
    byte[] bs = new byte[config.messageSize];
    ThreadLocalRandom r = ThreadLocalRandom.current();
    r.nextBytes(bs);

    ByteBuffer buf = ByteBuffer.wrap(bs);
    buf.putLong(config.batchId);
    long sendMachineId = START_TIME << 32;
    long msgId = sendMachineId | MSG_COUNT.getAndIncrement();
    buf.putLong(msgId);

    // save send tx result in message
    if (r.nextDouble() < config.sendRollbackRate) {
        buf.put((byte) LocalTransactionState.ROLLBACK_MESSAGE.ordinal());
    } else if (r.nextDouble() < config.sendUnknownRate) {
        buf.put((byte) LocalTransactionState.UNKNOW.ordinal());
    } else {
        buf.put((byte) LocalTransactionState.COMMIT_MESSAGE.ordinal());
    }

    // save check tx result in message
    for (int i = 0; i < MAX_CHECK_RESULT_IN_MSG; i++) {
        if (r.nextDouble() < config.checkRollbackRate) {
            buf.put((byte) LocalTransactionState.ROLLBACK_MESSAGE.ordinal());
        } else if (r.nextDouble() < config.checkUnknownRate) {
            buf.put((byte) LocalTransactionState.UNKNOW.ordinal());
        } else {
            buf.put((byte) LocalTransactionState.COMMIT_MESSAGE.ordinal());
        }
    }

    Message msg = new Message();
    msg.setTopic(config.topic);

    msg.setBody(bs);
    return msg;
}
 
Example #22
Source File: TransactionCheckListenerImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: TransactionExecuterImpl.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) {
    int value = transactionIndex.getAndIncrement();

    if (value == 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 #24
Source File: TransactionListenerImpl.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 #25
Source File: DefaultMQProducerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public void endTransaction(
    final SendResult sendResult,
    final LocalTransactionState localTransactionState,
    final Throwable localException) throws RemotingException, MQBrokerException, InterruptedException, UnknownHostException {
    final MessageId id;
    if (sendResult.getOffsetMsgId() != null) {
        id = MessageDecoder.decodeMessageId(sendResult.getOffsetMsgId());
    } else {
        id = MessageDecoder.decodeMessageId(sendResult.getMsgId());
    }
    String transactionId = sendResult.getTransactionId();
    final String brokerAddr = this.mQClientFactory.findBrokerAddressInPublish(sendResult.getMessageQueue().getBrokerName());
    EndTransactionRequestHeader requestHeader = new EndTransactionRequestHeader();
    requestHeader.setTransactionId(transactionId);
    requestHeader.setCommitLogOffset(id.getOffset());
    switch (localTransactionState) {
        case COMMIT_MESSAGE:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_COMMIT_TYPE);
            break;
        case ROLLBACK_MESSAGE:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_ROLLBACK_TYPE);
            break;
        case UNKNOW:
            requestHeader.setCommitOrRollback(MessageSysFlag.TRANSACTION_NOT_TYPE);
            break;
        default:
            break;
    }

    requestHeader.setProducerGroup(this.defaultMQProducer.getProducerGroup());
    requestHeader.setTranStateTableOffset(sendResult.getQueueOffset());
    requestHeader.setMsgId(sendResult.getMsgId());
    String remark = localException != null ? ("executeLocalTransactionBranch exception: " + localException.toString()) : null;
    this.mQClientFactory.getMQClientAPIImpl().endTransactionOneway(brokerAddr, requestHeader, remark,
        this.defaultMQProducer.getSendMsgTimeout());
}
 
Example #26
Source File: TransactionProducer.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState checkLocalTransactionState(MessageExt msg) {
    statsBenchmarkTProducer.getCheckRequestSuccessCount().incrementAndGet();
    if (ischeckffalse) {

        return LocalTransactionState.ROLLBACK_MESSAGE;
    }

    return LocalTransactionState.COMMIT_MESSAGE;
}
 
Example #27
Source File: TransactionProducer.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) {
    if (ischeck) {
        return LocalTransactionState.UNKNOW;
    }
    return LocalTransactionState.COMMIT_MESSAGE;
}
 
Example #28
Source File: TransactionCheckListenerImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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 #29
Source File: TransactionExecuterImpl.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Override
public LocalTransactionState executeLocalTransactionBranch(final Message msg, final Object arg) {
    int value = transactionIndex.getAndIncrement();

    if (value == 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 #30
Source File: TransactionListenerImpl.java    From java-tutorial with MIT License 5 votes vote down vote up
/**
 * 执行本地事务
 *
 * @param message
 * @param o
 * @return
 */
@Override
public LocalTransactionState executeLocalTransaction(Message message, Object o) {
    int value = transactionIndex.getAndIncrement();
    int status = value % 3;
    localTrans.put(message.getTransactionId(), status);

    return LocalTransactionState.UNKNOW;
}