diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/TransactionalResult.java b/openmessaging-api/src/main/java/io/openmessaging/api/TransactionalResult.java new file mode 100644 index 00000000..10100e94 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/TransactionalResult.java @@ -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(); + +} \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java index 99cf519b..dad031a8 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java @@ -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. @@ -46,4 +47,18 @@ public interface TransactionProducer extends Admin { SendResult send(final Message message, final LocalTransactionExecuter localTransactionExecutor, final Object arg); + + /** + * Sends a transactional message + *

+ * 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. + *

+ * + * @param message a prepare transactional message will be sent. + * @return the successful {@code TransactionalResult}. + */ + TransactionalResult prepare(Message message); }