Skip to content

Commit

Permalink
Merge pull request #66 from superhx/feat/two_phase_txn_msg
Browse files Browse the repository at this point in the history
feat(TransactionProducer): Add two phase transactional message support
  • Loading branch information
duhenglucky authored Mar 21, 2020
2 parents 1de47c5 + 276b839 commit bfbd77a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.openmessaging.api;

/**
* The result of sending a OMS prepare message, this result can be used to commits or or rollback a prepare message.
*
* @version OMS 2.0.1
* @since OMS 2.0.1
*/
public abstract class TransactionalResult extends SendResult {

/**
* Commits a transaction.
*/
public abstract void commit();

/**
* Rolls back a transaction.
*/
public abstract void rollback();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.openmessaging.api.Admin;
import io.openmessaging.api.Message;
import io.openmessaging.api.SendResult;
import io.openmessaging.api.TransactionalResult;

/**
* Send transactional message.
Expand All @@ -46,4 +47,18 @@ public interface TransactionProducer extends Admin {
SendResult send(final Message message,
final LocalTransactionExecuter localTransactionExecutor,
final Object arg);

/**
* Sends a transactional message
* <p>
* A transactional send result will be exposed to consumer if this prepare message send success, and then, you can
* execute your local transaction, when local transaction execute success, users can use {@link
* TransactionalResult#commit()} to commit prepare message,otherwise can use {@link TransactionalResult#rollback()}
* to roll back this prepare message.
* </p>
*
* @param message a prepare transactional message will be sent.
* @return the successful {@code TransactionalResult}.
*/
TransactionalResult prepare(Message message);
}

0 comments on commit bfbd77a

Please sign in to comment.