-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,624 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>rocketmq-all</artifactId> | ||
<groupId>org.apache.rocketmq</groupId> | ||
<version>5.0.0-BETA-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>jar</packaging> | ||
<artifactId>rocketmq-apis</artifactId> | ||
<name>rocketmq-apis ${project.version}</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
61 changes: 61 additions & 0 deletions
61
apis/src/main/java/org/apache/rocketmq/apis/ClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Common client configuration. | ||
*/ | ||
public class ClientConfiguration { | ||
private final String endpoints; | ||
private final SessionCredentialsProvider sessionCredentialsProvider; | ||
private final Duration requestTimeout; | ||
private final boolean enableTracing; | ||
|
||
public static ClientConfigurationBuilder newBuilder() { | ||
return new ClientConfigurationBuilder(); | ||
} | ||
|
||
public ClientConfiguration(String endpoints, SessionCredentialsProvider sessionCredentialsProvider, | ||
Duration requestTimeout, boolean enableTracing) { | ||
this.endpoints = checkNotNull(endpoints, "endpoints should not be null"); | ||
this.sessionCredentialsProvider = checkNotNull(sessionCredentialsProvider, "credentialsProvider should not be" | ||
+ " null"); | ||
this.requestTimeout = checkNotNull(requestTimeout, "requestTimeout should be not null"); | ||
this.enableTracing = enableTracing; | ||
} | ||
|
||
public String getEndpoints() { | ||
return endpoints; | ||
} | ||
|
||
public SessionCredentialsProvider getCredentialsProvider() { | ||
return sessionCredentialsProvider; | ||
} | ||
|
||
public Duration getRequestTimeout() { | ||
return requestTimeout; | ||
} | ||
|
||
public boolean isEnableTracing() { | ||
return enableTracing; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
apis/src/main/java/org/apache/rocketmq/apis/ClientConfigurationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Builder to set {@link ClientConfiguration}. | ||
*/ | ||
public class ClientConfigurationBuilder { | ||
private String endpoints; | ||
private SessionCredentialsProvider sessionCredentialsProvider; | ||
private Duration requestTimeout; | ||
private boolean enableTracing; | ||
|
||
/** | ||
* Configure the endpoints with which the SDK should communicate. | ||
* | ||
* <p>Endpoints here means address of service, complying with the following scheme(part square brackets is | ||
* optional). | ||
* <p>1. DNS scheme(default): dns:host[:port], host is the host to resolve via DNS, port is the port to return | ||
* for each address. If not specified, 443 is used. | ||
* <p>2. ipv4 scheme: ipv4:address:port[,address:port,...] | ||
* <p>3. ipv6 scheme: ipv6:address:port[,address:port,...] | ||
* <p>4. http/https scheme: http|https://host[:port], similar to DNS scheme, if port not specified, 443 is used. | ||
* | ||
* @param endpoints address of service. | ||
* @return the client configuration builder instance. | ||
*/ | ||
public ClientConfigurationBuilder setEndpoints(String endpoints) { | ||
checkNotNull(endpoints, "endpoints should not be not null"); | ||
this.endpoints = endpoints; | ||
return this; | ||
} | ||
|
||
public ClientConfigurationBuilder setCredentialProvider(SessionCredentialsProvider sessionCredentialsProvider) { | ||
this.sessionCredentialsProvider = checkNotNull(sessionCredentialsProvider, "credentialsProvider should not be " | ||
+ "null"); | ||
return this; | ||
} | ||
|
||
public ClientConfigurationBuilder setRequestTimeout(Duration requestTimeout) { | ||
this.requestTimeout = checkNotNull(requestTimeout, "requestTimeout should not be not null"); | ||
return this; | ||
} | ||
|
||
public ClientConfigurationBuilder enableTracing(boolean enableTracing) { | ||
this.enableTracing = enableTracing; | ||
return this; | ||
} | ||
|
||
public ClientConfiguration build() { | ||
return new ClientConfiguration(endpoints, sessionCredentialsProvider, requestTimeout, enableTracing); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
apis/src/main/java/org/apache/rocketmq/apis/ClientServiceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Iterator; | ||
import java.util.ServiceLoader; | ||
import org.apache.rocketmq.apis.message.MessageBuilder; | ||
import org.apache.rocketmq.apis.producer.ProducerBuilder; | ||
|
||
/** | ||
* Service provider to seek client, which load client according to | ||
* <a href="https://en.wikipedia.org/wiki/Service_provider_interface">Java SPI mechanism</a>. | ||
*/ | ||
public interface ClientServiceProvider { | ||
static ClientServiceProvider loadService() { | ||
final ServiceLoader<ClientServiceProvider> loaders = ServiceLoader.load(ClientServiceProvider.class); | ||
final Iterator<ClientServiceProvider> iterators = loaders.iterator(); | ||
if (iterators.hasNext()) { | ||
return iterators.next(); | ||
} | ||
throw new UnsupportedOperationException("Client service provider not found"); | ||
} | ||
|
||
/** | ||
* Get the producer builder by current provider. | ||
* | ||
* @return the producer builder instance. | ||
*/ | ||
ProducerBuilder newProducerBuilder(); | ||
|
||
/** | ||
* Get the message builder by current provider. | ||
* | ||
* @return the message builder instance. | ||
*/ | ||
MessageBuilder newMessageBuilder(); | ||
} |
24 changes: 24 additions & 0 deletions
24
apis/src/main/java/org/apache/rocketmq/apis/MessageQueue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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; | ||
|
||
public interface MessageQueue { | ||
String getTopic(); | ||
|
||
String getId(); | ||
} |
58 changes: 58 additions & 0 deletions
58
apis/src/main/java/org/apache/rocketmq/apis/SessionCredentials.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Session credentials used in service authentications. | ||
*/ | ||
public class SessionCredentials { | ||
private final String accessKey; | ||
private final String accessSecret; | ||
private final String securityToken; | ||
|
||
public SessionCredentials(String accessKey, String accessSecret, String securityToken) { | ||
this.accessKey = checkNotNull(accessKey, "accessKey should not be null"); | ||
this.accessSecret = checkNotNull(accessSecret, "accessSecret should not be null"); | ||
this.securityToken = checkNotNull(securityToken, "securityToken should not be null"); | ||
} | ||
|
||
public SessionCredentials(String accessKey, String accessSecret) { | ||
this.accessKey = checkNotNull(accessKey, "accessKey should not be null"); | ||
this.accessSecret = checkNotNull(accessSecret, "accessSecret should not be null"); | ||
this.securityToken = null; | ||
} | ||
|
||
public String getAccessKey() { | ||
return accessKey; | ||
} | ||
|
||
public String getAccessSecret() { | ||
return accessSecret; | ||
} | ||
|
||
public Optional<String> getSecurityToken() { | ||
if (null == securityToken) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(securityToken); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
apis/src/main/java/org/apache/rocketmq/apis/SessionCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Abstract provider to provide {@link SessionCredentials}. | ||
*/ | ||
public interface SessionCredentialsProvider { | ||
/** | ||
* Get the provided credentials. | ||
* | ||
* @return provided credentials. | ||
*/ | ||
SessionCredentials getCredentials(); | ||
} |
35 changes: 35 additions & 0 deletions
35
apis/src/main/java/org/apache/rocketmq/apis/StaticSessionCredentialsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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; | ||
|
||
public class StaticSessionCredentialsProvider implements SessionCredentialsProvider { | ||
private final SessionCredentials credentials; | ||
|
||
public StaticSessionCredentialsProvider(String accessKey, String accessSecret) { | ||
this.credentials = new SessionCredentials(accessKey, accessSecret); | ||
} | ||
|
||
public StaticSessionCredentialsProvider(String accessKey, String accessSecret, String securityToken) { | ||
this.credentials = new SessionCredentials(accessKey, accessSecret, securityToken); | ||
} | ||
|
||
@Override | ||
public SessionCredentials getCredentials() { | ||
return credentials; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
apis/src/main/java/org/apache/rocketmq/apis/exception/AuthenticationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.exception; | ||
|
||
/** | ||
* The difference between {@link AuthorisationException} and {@link AuthenticationException} is that | ||
* {@link AuthenticationException} here means current user's identity could not be recognized. | ||
* | ||
* <p>For example, {@link AuthenticationException} will be thrown if access key is invalid. | ||
*/ | ||
public class AuthenticationException extends ClientException { | ||
public AuthenticationException(ErrorCode code, String message, String requestId) { | ||
super(code, message); | ||
putMetadata(REQUEST_ID_KEY, requestId); | ||
} | ||
} |
Oops, something went wrong.