Skip to content

Commit bfbd77a

Browse files
authored
Merge pull request #66 from superhx/feat/two_phase_txn_msg
feat(TransactionProducer): Add two phase transactional message support
2 parents 1de47c5 + 276b839 commit bfbd77a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.openmessaging.api;
18+
19+
/**
20+
* The result of sending a OMS prepare message, this result can be used to commits or or rollback a prepare message.
21+
*
22+
* @version OMS 2.0.1
23+
* @since OMS 2.0.1
24+
*/
25+
public abstract class TransactionalResult extends SendResult {
26+
27+
/**
28+
* Commits a transaction.
29+
*/
30+
public abstract void commit();
31+
32+
/**
33+
* Rolls back a transaction.
34+
*/
35+
public abstract void rollback();
36+
37+
}

openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.openmessaging.api.Admin;
2121
import io.openmessaging.api.Message;
2222
import io.openmessaging.api.SendResult;
23+
import io.openmessaging.api.TransactionalResult;
2324

2425
/**
2526
* Send transactional message.
@@ -46,4 +47,18 @@ public interface TransactionProducer extends Admin {
4647
SendResult send(final Message message,
4748
final LocalTransactionExecuter localTransactionExecutor,
4849
final Object arg);
50+
51+
/**
52+
* Sends a transactional message
53+
* <p>
54+
* A transactional send result will be exposed to consumer if this prepare message send success, and then, you can
55+
* execute your local transaction, when local transaction execute success, users can use {@link
56+
* TransactionalResult#commit()} to commit prepare message,otherwise can use {@link TransactionalResult#rollback()}
57+
* to roll back this prepare message.
58+
* </p>
59+
*
60+
* @param message a prepare transactional message will be sent.
61+
* @return the successful {@code TransactionalResult}.
62+
*/
63+
TransactionalResult prepare(Message message);
4964
}

0 commit comments

Comments
 (0)