aaron-ai commented on a change in pull request #3987: URL: https://github.com/apache/rocketmq/pull/3987#discussion_r827066394
########## File path: apis/src/main/java/org/apache/rocketmq/apis/producer/Producer.java ########## @@ -0,0 +1,140 @@ +/* + * 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 org.apache.rocketmq.apis.producer; + +import com.google.common.util.concurrent.Service; +import java.util.concurrent.CompletableFuture; +import java.io.Closeable; +import java.util.Collection; +import org.apache.rocketmq.apis.exception.AuthenticationException; +import org.apache.rocketmq.apis.exception.AuthorisationException; +import org.apache.rocketmq.apis.exception.ClientException; +import org.apache.rocketmq.apis.exception.MessageTypeDoesNotMatchException; +import org.apache.rocketmq.apis.exception.PersistenceException; +import org.apache.rocketmq.apis.exception.ProducerClosedAlreadyException; +import org.apache.rocketmq.apis.exception.NetworkConnectionException; +import org.apache.rocketmq.apis.exception.NetworkTimeoutException; +import org.apache.rocketmq.apis.exception.TopicDoesNotExistException; +import org.apache.rocketmq.apis.exception.TransactionCheckerNotSetException; +import org.apache.rocketmq.apis.message.Message; +import org.apache.rocketmq.apis.message.MessageView; + +/** + * Producer is a thread-safe rocketmq client which is used to publish messages. + * + * <p>On account of network timeout or other reasons, rocketmq producer only promised the at-least-once semantics. + * For producer, at-least-once semantics means potentially attempts are made at sending it, messages may be + * duplicated but not lost. + */ +public interface Producer extends Closeable { + /** + * Sends a message synchronously. + * + * <p>This method does not return until it gets the definitive result. + * + * @param message message to send. + * @return the message id assigned to the appointed message. + * @throws TopicDoesNotExistException if the topic of message does not exist. + * @throws AuthorisationException if no permission to send message. + * @throws AuthenticationException if identification could not be recognized by server. + * @throws ProducerClosedAlreadyException if producer is closed already. + * @throws MessageTypeDoesNotMatchException if message type does not match with the topic. + * @throws NetworkTimeoutException if encountered network timeout to communicate with server. + * @throws NetworkConnectionException if there is a network connection problem. + * @throws PersistenceException if encountered persistence failure from server. + */ + MessageView send(Message message) throws ClientException; + + /** + * Sends a transactional message synchronously. + * + * @param message message to send. + * @param transaction transaction to bind. + * @return the message id assigned to the appointed message. + * @throws TopicDoesNotExistException if the topic of message does not exist. + * @throws AuthorisationException if no permission to send message. + * @throws AuthenticationException if identification could not be recognized by server. + * @throws ProducerClosedAlreadyException if producer is closed already. + * @throws MessageTypeDoesNotMatchException if message type does not match with the topic. + * @throws NetworkTimeoutException if encountered network timeout to communicate with server. + * @throws NetworkConnectionException if there is a network connection problem. + * @throws PersistenceException if encountered persistence failure from server. + * @throws TransactionCheckerNotSetException if {@link TransactionChecker} is not set. + */ + MessageView send(Message message, Transaction transaction) throws ClientException; Review comment: > These exceptions are unchecked, which means we don't want our users to use these exceptions to control their logic, so a simple ClientException is enough. First of all, exceptions are inevitable. In fact, about the issue that whether to use checked exception or not, maybe no need to prevent users to do responding operation by the exception thrown deliberately? For example, users just want to count how many times the network timeout exception occurred. In addition, about the issue to use error codes or specific exception, actuall they can all solve the problem in theory, here's my concern 1. It is very easy to abuse error code. 2. Not all exceptions will have the same parameters, such as requestId, they may only exist in some exceptions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
