客户端接口字典
消息客户端接口定义参考
public interface MqClient extends Closeable {
//获取名字
String name();
//配置名字(即默认的消费者组)
MqClient nameAs(String name);
//连接
MqClient connect() throws IOException;
//断开连接
void disconnect() throws IOException;
//客户端配置
MqClient config(ClientConfigHandler configHandler);
//消费执行器(就是指定消费线程池)
MqClient consumeExecutor(ExecutorService consumeExecutor);
//配置自动回执
MqClient autoAcknowledge(boolean auto);
//是否自动回执
boolean autoAcknowledge();
//接口管理调用
CompletableFuture<String> call(String apiName, String apiToken, String topic, String consumerGroup) throws IOException;
/**
* 订阅主题
*
* @param topic 主题
* @param consumerGroup 消费者组
* @param autoAck 是否自动回执
* @param consumerHandler 消费处理
*/
void subscribe(String topic, String consumerGroup, boolean autoAck, MqConsumeHandler consumerHandler) throws IOException;
/**
* 订阅主题
*
* @param topic 主题
* @param consumerGroup 消费者组
* @param consumerHandler 消费处理
*/
default void subscribe(String topic, String consumerGroup, MqConsumeHandler consumerHandler) throws IOException {
subscribe(topic, consumerGroup, autoAcknowledge(), consumerHandler);
}
/**
* 订阅主题
*
* @param topic 主题
* @param consumerHandler 消费处理
*/
default void subscribe(String topic, MqConsumeHandler consumerHandler) throws IOException {
//检查必要条件
if (StrUtils.isEmpty(name())) {
throw new IllegalArgumentException("Client 'name' can't be empty");
}
subscribe(topic, name(), autoAcknowledge(), consumerHandler);
}
/**
* 取消订阅主题
*
* @param topic 主题
* @param consumerGroup 消费者组
*/
void unsubscribe(String topic, String consumerGroup) throws IOException;
/**
* 取消订阅主题
*
* @param topic 主题
*/
default void unsubscribe(String topic) throws IOException {
//检查必要条件
if (StrUtils.isEmpty(name())) {
throw new IllegalArgumentException("Client 'name' can't be empty");
}
unsubscribe(topic, name());
}
/**
* 同步发布消息
*
* @param topic 主题
* @param message 消息
*/
void publish(String topic, MqMessage message) throws IOException;
/**
* 异步发布消息
*
* @param topic 主题
* @param message 消息
*/
CompletableFuture<Boolean> publishAsync(String topic, MqMessage message) throws IOException;
/**
* 取消发布
*
* @param topic 主题
* @param tid 跟踪id
*/
void unpublish(String topic, String tid) throws IOException;
/**
* 取消发布
*
* @param topic 主题
* @param tid 跟踪id
*/
CompletableFuture<Boolean> unpublishAsync(String topic, String tid) throws IOException;
//配置事务回查接口
MqClient transactionCheckback(MqTransactionCheckback transactionCheckback);
/**
* 新建事务
*/
MqTransaction newTransaction();
}