diff --git a/.travis.yml b/.travis.yml index 7047779b..76da1a34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ -language: java +dist: trusty -addons: - apt: - packages: - - openjdk-6-jdk +language: java install: - echo "Downloading Maven 3.0"; @@ -17,10 +14,11 @@ install: jdk: - oraclejdk8 - oraclejdk9 -- openjdk7 -- openjdk6 +- oraclejdk11 +- openjdk8 + -script: mvn install +script: mvn clean install env: global: secure: hmPdcALAi6qE3TqJDRqdVCqZftd/i2hWLCyZbIAcRzu38nO94JZYKSZjfif1FvXTJYotFW25JClXNyvOMwMjjK3OPQINfYFZIp6LLeOmXGbUcktwQ8TIoKZ7IOvvWiZK054H7zNKapz+ke3OPN/5WTmMBezV0Ct4+bSf9udKVnQSMG2sJ8YJ/SeZkh7RTlqO+zTkh+yq8Hk0BdaWEOK8RtEoWgcUFGVfkycvjgvna+TbDp3K7vjmhYBBqACsNKxXPgIumStbCGW4vwjoVkCOGIJKWnuQEVHxiqBUH3pp81bxnt+RIcMuZMR2HnDSpHyAIulTJNHVo3VFAAiy9HMdP8Wfy/OVdjBSZ8xIOoQvFijo+yGNNn8v4hILcX4IpumQeyjpG134BOWVbMLhKH7qWR3Z8TGgijSd4lYYjabCJ564E93KvqK1u2CuS9u89N8J7AKFYMbknH1DP8E5tCD+VI3Gwut9YNofywj3Jln8uCOP4I//8p61j9A9QF7ORpY59Ru4RNzxYrFn2QSTltMfaBfVZchh5AqURUamcJd+1orZfz/v+6yH9FOW+MAG8EJdzHDsqzP1NXrt+4VtF6yqOnhBxnKVNEwFwjsinW9PFi9dXyzdEd33jKGL7UO8Old5XlBoA7idWIDH4GKKSlBRZhEKWMe4ZfxpQVg3VPz2Qqo= diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index debe8f13..9b172e46 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.0.0-beta-SNAPSHOT + 2.0.2-pubsub-SNAPSHOT 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index d35c519d..f62c70f1 100644 --- a/openmessaging-api-samples/pom.xml +++ b/openmessaging-api-samples/pom.xml @@ -2,13 +2,13 @@ io.openmessaging parent - 1.0.0-beta-SNAPSHOT + 2.0.2-pubsub-SNAPSHOT 4.0.0 jar openmessaging-api-samples - 1.0.0-beta-SNAPSHOT + 2.0.2-pubsub-SNAPSHOT openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 1.0.0-beta-SNAPSHOT + 2.0.2-pubsub-SNAPSHOT org.slf4j diff --git a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PullConsumerApp.java b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PullConsumerApp.java index 7f9a2e85..c16d83bf 100644 --- a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PullConsumerApp.java +++ b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PullConsumerApp.java @@ -17,37 +17,46 @@ package io.openmessaging.samples.consumer; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.consumer.PullConsumer; -import io.openmessaging.message.Message; -import java.util.Arrays; +import io.openmessaging.api.Message; +import io.openmessaging.api.MessagingAccessPoint; +import io.openmessaging.api.OMS; +import io.openmessaging.api.PullConsumer; +import io.openmessaging.api.TopicPartition; +import java.util.List; +import java.util.Properties; +import java.util.Set; public class PullConsumerApp { public static void main(String[] args) { //Load and start the vendor implementation from a specific OMS driver URL. final MessagingAccessPoint messagingAccessPoint = - OMS.getMessagingAccessPoint("oms:rocketmq://alice@rocketmq.apache.org/us-east"); + OMS.builder() + .endpoint("http://mq-instance-xxx-1234567890-test:8080") + .region("Shenzhen") + .driver("rocketmq") + .build(); + Properties properties = new Properties(); //Start a PullConsumer to receive messages from the specific queue. - final PullConsumer consumer = messagingAccessPoint.createPullConsumer(); + final PullConsumer consumer = messagingAccessPoint.createPullConsumer(properties); //Register a shutdown hook to close the opened endpoints. Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { - consumer.stop(); + consumer.shutdown(); } })); - consumer.bindQueue(Arrays.asList("NS://HELLO_QUEUE")); + Set topicPartitions = consumer.topicPartitions("NS://TOPIC"); + consumer.assign(topicPartitions); consumer.start(); - Message message = consumer.receive(1000); + List message = consumer.poll(1000); System.out.println("Received message: " + message); //Acknowledge the consumed message - consumer.ack(message.getMessageReceipt()); - consumer.stop(); + consumer.commitSync(); + consumer.shutdown(); } } diff --git a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PushConsumerApp.java b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PushConsumerApp.java index 47ea14eb..2b48fdaa 100644 --- a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PushConsumerApp.java +++ b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PushConsumerApp.java @@ -17,51 +17,50 @@ package io.openmessaging.samples.consumer; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.consumer.Consumer; -import io.openmessaging.consumer.MessageListener; -import io.openmessaging.consumer.PushConsumer; -import io.openmessaging.manager.ResourceManager; -import io.openmessaging.message.Message; -import java.util.Arrays; +import io.openmessaging.api.Action; +import io.openmessaging.api.ConsumeContext; +import io.openmessaging.api.Consumer; +import io.openmessaging.api.Message; +import io.openmessaging.api.MessageListener; +import io.openmessaging.api.MessagingAccessPoint; +import io.openmessaging.api.OMS; +import java.util.Properties; public class PushConsumerApp { public static void main(String[] args) { //Load and start the vendor implementation from a specific OMS driver URL. final MessagingAccessPoint messagingAccessPoint = - OMS.getMessagingAccessPoint("oms:rocketmq://localhost:10911/us-east"); + OMS.builder() + .region("Shenzhen") + .endpoint("127.0.0.1:9876") + .driver("rocketmq") + .withCredentials(new Properties()) + .build(); - //Fetch a ResourceManager to create Queue resource. - ResourceManager resourceManager = messagingAccessPoint.resourceManager(); - resourceManager.createNamespace("NS://XXXX"); - final PushConsumer consumer = messagingAccessPoint.createPushConsumer(); + Properties properties = new Properties(); + final Consumer consumer = messagingAccessPoint.createConsumer(properties); consumer.start(); //Register a shutdown hook to close the opened endpoints. Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { - consumer.stop(); + consumer.shutdown(); } })); //Consume messages from a simple queue. - String simpleQueue = "NS://HELLO_QUEUE"; - resourceManager.createQueue(simpleQueue); - //This queue doesn't has a source queue, so only the message delivered to the queue directly can - //be consumed by this consumer. - consumer.bindQueue(Arrays.asList(simpleQueue), new MessageListener() { + String topic = "NS://HELLO_TOPIC"; + + consumer.subscribe(topic, "*", new MessageListener(){ @Override - public void onReceived(Message message, Context context) { - System.out.println("Received one message: " + message); - context.ack(); - } + public Action consume(Message message, ConsumeContext context) { + return Action.CommitMessage; + } }); - consumer.unbindQueue(Arrays.asList(simpleQueue)); - consumer.stop(); + consumer.shutdown(); } } \ No newline at end of file diff --git a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/ProducerApp.java b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/ProducerApp.java index 9084b8a8..117e0f80 100644 --- a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/ProducerApp.java +++ b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/ProducerApp.java @@ -17,71 +17,57 @@ package io.openmessaging.samples.producer; -import io.openmessaging.Future; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.interceptor.Context; -import io.openmessaging.interceptor.ProducerInterceptor; -import io.openmessaging.message.Message; -import io.openmessaging.producer.Producer; -import io.openmessaging.producer.SendResult; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; +import io.openmessaging.api.Message; +import io.openmessaging.api.MessagingAccessPoint; +import io.openmessaging.api.OMS; +import io.openmessaging.api.OnExceptionContext; +import io.openmessaging.api.Producer; +import io.openmessaging.api.SendCallback; +import io.openmessaging.api.SendResult; +import java.util.Properties; public class ProducerApp { public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = - OMS.getMessagingAccessPoint("oms:rocketmq://alice@rocketmq.apache.org/us-east"); + OMS.builder() + .region("shanghai,shenzhen") + .endpoint("127.0.0.1:9876") + .driver("rocketmq") + .withCredentials(new Properties()) + .build(); - final Producer producer = messagingAccessPoint.createProducer(); - ProducerInterceptor interceptor = new ProducerInterceptor() { - @Override - public void preSend(Message message, Context attributes) { - System.out.println("PreSend message: " + message); - } - - @Override - public void postSend(Message message, Context attributes) { - System.out.println("PostSend message: " + message); - } - }; - producer.addInterceptor(interceptor); + final Producer producer = messagingAccessPoint.createProducer(new Properties()); producer.start(); //Register a shutdown hook to close the opened endpoints. Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { - producer.stop(); + producer.shutdown(); } })); - //Send a message to the specified destination synchronously. - Message message = producer.createMessage( - "NS://HELLO_QUEUE1", "HELLO_BODY".getBytes(Charset.forName("UTF-8"))); - message.header().setBornHost("127.0.0.1").setDurability((short) 0); - message.extensionHeader().setPartition(1); + Message message = new Message("NS://Topic", "TagA", "Hello MQ".getBytes()); + SendResult sendResult = producer.send(message); System.out.println("SendResult: " + sendResult); //Sends a message to the specified destination async. - Future sendResultFuture = producer.sendAsync(message); - sendResult = sendResultFuture.get(1000); - System.out.println("SendResult: " + sendResult); + producer.sendAsync(message, new SendCallback() { + @Override + public void onSuccess(SendResult sendResult) { + System.out.println("SendResult: " + sendResult); + } + + @Override + public void onException(OnExceptionContext context) { + + } + }); //Sends a message to the specified destination in one way mode. producer.sendOneway(message); - //Sends messages to the specified destination in batch mode. - List messages = new ArrayList(10); - for (int i = 0; i < 10; i++) { - Message msg = producer.createMessage("NS://HELLO_QUEUE", ("Hello" + i).getBytes()); - messages.add(msg); - } - - producer.send(messages); - producer.removeInterceptor(interceptor); - producer.stop(); + producer.shutdown(); } } diff --git a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/TransactionProducerApp.java b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/TransactionProducerApp.java index bed57642..a8abbb3a 100644 --- a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/TransactionProducerApp.java +++ b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/TransactionProducerApp.java @@ -17,22 +17,30 @@ package io.openmessaging.samples.producer; -import io.openmessaging.message.Message; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.producer.Producer; -import io.openmessaging.producer.TransactionStateCheckListener; -import io.openmessaging.producer.TransactionalResult; -import java.nio.charset.Charset; +import io.openmessaging.api.Message; +import io.openmessaging.api.MessagingAccessPoint; +import io.openmessaging.api.OMS; +import io.openmessaging.api.SendResult; +import io.openmessaging.api.transaction.LocalTransactionChecker; +import io.openmessaging.api.transaction.LocalTransactionExecuter; +import io.openmessaging.api.transaction.TransactionProducer; +import io.openmessaging.api.transaction.TransactionStatus; +import java.util.Properties; public class TransactionProducerApp { public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = - OMS.getMessagingAccessPoint("oms:rocketmq://alice@rocketmq.apache.org/us-east"); - - final Producer producer = messagingAccessPoint.createProducer(new TransactionStateCheckListener() { - @Override public void check(Message message, TransactionalContext context) { + OMS.builder() + .region("Shenzhen") + .endpoint("127.0.0.1:9876") + .driver("rocketmq") + .withCredentials(new Properties()) + .build(); + final TransactionProducer producer = messagingAccessPoint.createTransactionProducer(new Properties(), new LocalTransactionChecker() { + @Override + public TransactionStatus check(Message msg) { + return TransactionStatus.CommitTransaction; } }); producer.start(); @@ -41,23 +49,19 @@ public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { - producer.stop(); + producer.shutdown(); } })); - Message message = producer.createMessage( - "NS://HELLO_QUEUE", "HELLO_BODY".getBytes(Charset.forName("UTF-8"))); + Message message = new Message("NS://Topic", "TagA", "Hello MQ".getBytes()); //Sends a transaction message to the specified destination synchronously. - TransactionalResult result = producer.prepare(message); - executeLocalTransaction(result); - result.commit(); - producer.stop(); - System.out.println("Send transaction message OK, message id is: " + result.messageId()); + SendResult result = producer.send(message, new LocalTransactionExecuter() { + @Override public TransactionStatus execute(Message message, Object arg) { + return TransactionStatus.CommitTransaction; + } + }, null); + System.out.println("Send transaction message OK, message id is: " + result.getMessageId()); } - private static void executeLocalTransaction(TransactionalResult result) { - System.out.println("transactionId: " + result.transactionId()); - System.out.println("execute local transaction"); - } } diff --git a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/routing/RoutingApp.java b/openmessaging-api-samples/src/main/java/io/openmessaging/samples/routing/RoutingApp.java deleted file mode 100644 index 298655cc..00000000 --- a/openmessaging-api-samples/src/main/java/io/openmessaging/samples/routing/RoutingApp.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.samples.routing; - -import io.openmessaging.consumer.PushConsumer; -import io.openmessaging.message.Message; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.consumer.Consumer; -import io.openmessaging.consumer.MessageListener; -import io.openmessaging.manager.ResourceManager; -import io.openmessaging.producer.Producer; -import java.util.Arrays; - -public class RoutingApp { - public static void main(String[] args) { - //Load and start the vendor implementation from a specific OMS driver URL. - final MessagingAccessPoint messagingAccessPoint = - OMS.getMessagingAccessPoint("oms:rocketmq://alice@rocketmq.apache.org/us-east"); - - String destinationQueue = "NS://DESTINATION_QUEUE"; - String sourceQueue = "NS://SOURCE_QUEUE"; - //Fetch a ResourceManager to create source Queue, destination Queue, and the Routing instance. - ResourceManager resourceManager = messagingAccessPoint.resourceManager(); - - //Create the destination queue. - resourceManager.createQueue(destinationQueue); - //Create the source queue. - resourceManager.createQueue(sourceQueue); - - resourceManager.routing(sourceQueue, destinationQueue); - resourceManager.filter(destinationQueue, "name = 'kaka'"); - - //Send messages to the source queue ahead of the routing - final Producer producer = messagingAccessPoint.createProducer(); - producer.start(); - - Message message = producer.createMessage(sourceQueue, "RED_COLOR".getBytes()); - message.properties().put("color", "green").put("shape", "round"); - - producer.send(message); - - //Consume messages from the queue behind the routing. - final PushConsumer consumer = messagingAccessPoint.createPushConsumer(); - consumer.start(); - - consumer.bindQueue(Arrays.asList(destinationQueue), new MessageListener() { - @Override - public void onReceived(Message message, Context context) { - //The message sent to the sourceQueue will be delivered to anotherConsumer by the routing rule - //In this case, the push consumer will only receive the message with red color. - System.out.println("Received a red message: " + message); - context.ack(); - } - - }); - - //Register a shutdown hook to close the opened endpoints. - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - @Override - public void run() { - producer.stop(); - consumer.stop(); - } - })); - - } -} diff --git a/openmessaging-api/README.md b/openmessaging-api/README.md deleted file mode 100644 index 999ed6ac..00000000 --- a/openmessaging-api/README.md +++ /dev/null @@ -1,14 +0,0 @@ -## Server Side -* Namespace -* Queue - * Stream -* Routing - * Expression - -## Client Side -* Producer -* PushConsumer -* PullConsumer -* StreamingConsumer -* Message - * BytesMessage diff --git a/openmessaging-api/pom.xml b/openmessaging-api/pom.xml index 9e493ee9..bd53ce6c 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.0.0-beta-SNAPSHOT + 2.0.2-pubsub-SNAPSHOT 4.0.0 diff --git a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java deleted file mode 100644 index 9c617f2f..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/KeyValue.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * 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; - -import java.util.Set; - -/** - * The {@code KeyValue} class represents a persistent set of attributes, which supports method chaining. - *

- * A {@code KeyValue} object only allows {@code String} keys and can contain four primitive type as values: {@code int}, - * {@code long}, {@code double}, {@code String}. - *

- * The {@code KeyValue} is a replacement of {@code Properties}, with simpler interfaces and reasonable entry limits. - *

- * A {@code KeyValue} object may be used in concurrent scenarios, so the implementation of {@code KeyValue} should - * consider concurrent related issues. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface KeyValue { - - /** - * Inserts or replaces {@code boolean} value for the specified key. - * - * @param key the key to be placed into this {@code KeyValue} object - * @param value the value corresponding to key - */ - KeyValue put(String key, boolean value); - - /** - * Inserts or replaces {@code short} value for the specified key. - * - * @param key the key to be placed into this {@code KeyValue} object - * @param value the value corresponding to key - */ - KeyValue put(String key, short value); - - /** - * Inserts or replaces {@code int} value for the specified key. - * - * @param key the key to be placed into this {@code KeyValue} object - * @param value the value corresponding to key - */ - KeyValue put(String key, int value); - - /** - * Inserts or replaces {@code long} value for the specified key. - * - * @param key the key to be placed into this {@code KeyValue} object - * @param value the value corresponding to key - */ - KeyValue put(String key, long value); - - /** - * Inserts or replaces {@code double} value for the specified key. - * - * @param key the key to be placed into this {@code KeyValue} object - * @param value the value corresponding to key - */ - KeyValue put(String key, double value); - - /** - * Inserts or replaces {@code String} value for the specified key. - * - * @param key the key to be placed into this {@code KeyValue} object - * @param value the value corresponding to key - */ - KeyValue put(String key, String value); - - /** - * Searches for the {@code boolean} property with the specified key in this {@code KeyValue} object. If the key is - * not found in this property list, false is returned. - * - * @param key the property key - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, boolean) - */ - boolean getBoolean(String key); - - /** - * Searches for the {@code boolean} property with the specified key in this {@code KeyValue} object. If the key is - * not found in this property list, false is returned. - * - * @param key the property key - * @param defaultValue a default value - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, boolean) - */ - boolean getBoolean(String key, boolean defaultValue); - - /** - * Searches for the {@code short} property with the specified key in this {@code KeyValue} object. If the key is not - * found in this property list, zero is returned. - * - * @param key the property key - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, short) - */ - short getShort(String key); - - /** - * Searches for the {@code short} property with the specified key in this {@code KeyValue} object. If the key is not - * found in this property list, zero is returned. - * - * @param key the property key - * @param defaultValue a default value - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, short) - */ - short getShort(String key, short defaultValue); - - /** - * Searches for the {@code int} property with the specified key in this {@code KeyValue} object. If the key is not - * found in this property list, zero is returned. - * - * @param key the property key - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, int) - */ - int getInt(String key); - - /** - * Searches for the {@code int} property with the specified key in this {@code KeyValue} object. If the key is not - * found in this property list, the default value argument is returned. - * - * @param key the property key - * @param defaultValue a default value - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, int) - */ - int getInt(String key, int defaultValue); - - /** - * Searches for the {@code long} property with the specified key in this {@code KeyValue} object. If the key is not - * found in this property list, zero is returned. - * - * @param key the property key - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, long) - */ - long getLong(String key); - - /** - * Searches for the {@code long} property with the specified key in this {@code KeyValue} object. If the key is not - * found in this property list, the default value argument is returned. - * - * @param key the property key - * @param defaultValue a default value - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, long) - */ - long getLong(String key, long defaultValue); - - /** - * Searches for the {@code double} property with the specified key in this {@code KeyValue} object. If the key is - * not found in this property list, zero is returned. - * - * @param key the property key - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, double) - */ - double getDouble(String key); - - /** - * Searches for the {@code double} property with the specified key in this {@code KeyValue} object. If the key is - * not found in this property list, the default value argument is returned. - * - * @param key the property key - * @param defaultValue a default value - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, double) - */ - double getDouble(String key, double defaultValue); - - /** - * Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is - * not found in this property list, {@code null} is returned. - * - * @param key the property key - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, String) - */ - String getString(String key); - - /** - * Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is - * not found in this property list, the default value argument is returned. - * - * @param key the property key - * @param defaultValue a default value - * @return the value in this {@code KeyValue} object with the specified key value - * @see #put(String, String) - */ - String getString(String key, String defaultValue); - - /** - * Returns a {@link Set} view of the keys contained in this {@code KeyValue} object. - *

- * The set is backed by the {@code KeyValue}, so changes to the set are reflected in the @code KeyValue}, and - * vice-versa. - * - * @return the key set view of this {@code KeyValue} object. - */ - Set keySet(); - - /** - * Tests if the specified {@code String} is a key in this {@code KeyValue}. - * - * @param key possible key - * @return true if and only if the specified key is in this {@code KeyValue}, false - * otherwise. - */ - boolean containsKey(String key); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/OMS.java b/openmessaging-api/src/main/java/io/openmessaging/OMS.java deleted file mode 100644 index 4f3d9342..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/OMS.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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; - -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.internal.DefaultKeyValue; -import io.openmessaging.internal.MessagingAccessPointAdapter; -import io.openmessaging.manager.ResourceManager; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * The oms class provides some static methods to create a {@code MessagingAccessPoint} from the specified OMS driver url - * and some useful util methods. - *

- * The complete OMS driver URL syntax is: - *

- * {@literal oms:://[account_id@]host1[:port1][,host2[:port2],...[,hostN[:portN]]]/} - *

- * The first part of the URL specifies which OMS implementation is to be used, rocketmq is a optional driver type. - *

- * The brackets indicate that the extra access points are optional, and a correct OMS driver url needs at least one - * access point, which consists of hostname and port, like localhost:8081. - * - * @version OMS 1.0.0 - * @see ResourceManager - * @since OMS 1.0.0 - */ -public final class OMS { - /** - * Returns a {@code MessagingAccessPoint} instance from the specified OMS driver url. - * - * @param url the specified OMS driver url - * @return a {@code MessagingAccessPoint} instance - * @throws OMSRuntimeException if the factory fails to create a {@code MessagingAccessPoint} due to some driver url - * some syntax error or internal error. - */ - public static MessagingAccessPoint getMessagingAccessPoint(String url) { - return getMessagingAccessPoint(url, OMS.newKeyValue()); - } - - /** - * Returns a {@code MessagingAccessPoint} instance from the specified OMS driver url with some preset attributes, - * which will be passed to MessagingAccessPoint's implementation class as a unique constructor parameter. - * - * There are some standard attributes defined by OMS for this method, the same as {@link - * MessagingAccessPoint#attributes()} ()} - * - * @param url the specified OMS driver url - * @return a {@code MessagingAccessPoint} instance - * @throws OMSRuntimeException if the factory fails to create a {@code MessagingAccessPoint} due to some driver url - * some syntax error or internal error. - */ - public static MessagingAccessPoint getMessagingAccessPoint(String url, KeyValue attributes) { - return MessagingAccessPointAdapter.getMessagingAccessPoint(url, attributes); - } - - /** - * Returns a default and internal {@code KeyValue} implementation instance. - * - * @return a {@code KeyValue} instance - */ - public static KeyValue newKeyValue() { - return new DefaultKeyValue(); - } - - /** - * The version format is X.Y.Z (Major.Minor.Patch), a pre-release version may be denoted by appending a hyphen and a - * series of dot-separated identifiers immediately following the patch version, like X.Y.Z-alpha. - * - *

- * OMS version follows semver scheme partially. - * - * @see http://semver.org - */ - public static String specVersion = "UnKnown"; - - static { - InputStream stream = OMS.class.getClassLoader().getResourceAsStream("oms.spec.properties"); - try { - if (stream != null) { - Properties properties = new Properties(); - properties.load(stream); - specVersion = String.valueOf(properties.get("version")); - } - } catch (IOException ignore) { - } - } - - private OMS() { - } -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/Promise.java b/openmessaging-api/src/main/java/io/openmessaging/Promise.java deleted file mode 100644 index 58fbe767..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/Promise.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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; - -/** - * Special {@link Future} which is writable. - *

- * A {@code Promise} can be completed or canceled, cancellation is performed by the {@code cancel} method. - * Once a computation has completed, the computation cannot be cancelled. If you would like to use a {@code Promise} - * for the sake of cancellability but not provide a usable result, you can declare type+s of the form - * {@code Promise} and return {@code null} as a result of the underlying task. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface Promise extends Future { - - /** - * Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already - * been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started - * when {@code cancel} is called, this task should never run. If the task has already started, then the {@code - * mayInterruptIfRunning} parameter determines whether the thread executing this task should be interrupted in an - * attempt to stop the task. - *

- * After this method returns, subsequent calls to {@link #isDone} will always return {@code true}. Subsequent calls - * to {@link #isCancelled} will always return {@code true} if this method returned {@code true}. - * - * @param mayInterruptIfRunning {@code true} if the thread executing this task should be interrupted; otherwise, - * in-progress tasks are allowed to complete - * @return {@code false} if the task could not be cancelled, typically because it has already completed normally; - * {@code true} otherwise - */ - boolean cancel(boolean mayInterruptIfRunning); - - /** - * Set the value to this promise and mark it completed if set successfully. - * - * @param value Value - * @return Whether set is success - */ - boolean set(V value); - - /** - * Marks this promise as a failure and notifies all listeners. - * - * @param cause the cause - * @return Whether set is success - */ - boolean setFailure(Throwable cause); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/ServiceLifeState.java b/openmessaging-api/src/main/java/io/openmessaging/ServiceLifeState.java deleted file mode 100644 index eafdb18f..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/ServiceLifeState.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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; - -/** - * A collection of all service states. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public enum ServiceLifeState { - - /** - * Service has been initialized. - */ - INITIALIZED, - - /** - * Service in starting. - */ - STARTING, - - /** - * Service in running. - */ - STARTED, - - /** - * Service is stopping. - */ - STOPPING, - - /** - * Service has been stopped. - */ - STOPPED, -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/annotation/Optional.java b/openmessaging-api/src/main/java/io/openmessaging/annotation/Optional.java deleted file mode 100644 index b5b9d490..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/annotation/Optional.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - *

- * A {@code Optional} is an annotation to mark some certain methods ,interfaces and etc. this annotation represented - * these methods or interfaces are not mandatory in OpenMessaging. - *

- * - *

- * If these methods or interfaces adopted by more and more vendors and end users, they may be become the mandatory - * interface in the future. Of course, if they are used very little, they may be removed. - *

- * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PACKAGE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}) -public @interface Optional { -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Action.java b/openmessaging-api/src/main/java/io/openmessaging/api/Action.java new file mode 100644 index 00000000..851163fc --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Action.java @@ -0,0 +1,26 @@ +/* + * 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; + + +public enum Action { + + CommitMessage, + + ReconsumeLater, +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Admin.java b/openmessaging-api/src/main/java/io/openmessaging/api/Admin.java new file mode 100644 index 00000000..5fd24301 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Admin.java @@ -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 io.openmessaging.api; + +/** + *

+ * Client basic management interface, used for as a unified interface to manage basic operations such as start, stop, + * and authorization information management. + * + *

+ * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface Admin extends LifeCycle, Credentials { +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ConsumeContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/ConsumeContext.java new file mode 100644 index 00000000..e2f9996a --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ConsumeContext.java @@ -0,0 +1,21 @@ +/* + * 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; + +public class ConsumeContext { + +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java new file mode 100644 index 00000000..4ed9cec0 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java @@ -0,0 +1,57 @@ +/* + * 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; + +/** + * Consumer interface. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface Consumer extends Admin { + + /** + * Subscribe message in order. + * + * @param topic message topic. + * @param subExpression Subscribe to the filter expression string, which the broker filters based on this + * expression.
eg: "tag1 || tag2 || tag3"
, if subExpression is equal to null or *, it means subscribe all + * messages. + * @param listener The message callback listener, the consumer receives the message and then passes it to the + * message callback listener for consumption. + */ + void subscribe(final String topic, final String subExpression, final MessageListener listener); + + /** + * Subscribe to messages, which can be filtered using SQL expressions. + * + * @param topic + * @param selector Subscribe to the message selector (can be empty, indicating no filtering), the ONS server filters + * according to the expression in this selector. Currently supports two expression syntax: {@link + * ExpressionType#TAG}, {@link ExpressionType#SQL92} Among them, the effect of TAG filtering is consistent with the + * above interface. + * @param listener Message callback listener + */ + void subscribe(final String topic, final MessageSelector selector, final MessageListener listener); + + /** + * Unsubscribe message + * + * @param topic + */ + void unsubscribe(final String topic); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java b/openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java new file mode 100644 index 00000000..674b9db5 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java @@ -0,0 +1,34 @@ +/* + * 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; + +import java.util.Properties; + +/** + * + * Used for update credentials. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface Credentials { + /** + * Update credentials for instance, properties can be found in {@link OMSBuiltinKeys} + * @param credentialProperties + */ + void updateCredential(Properties credentialProperties); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java b/openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java new file mode 100644 index 00000000..64a444a3 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java @@ -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 io.openmessaging.api; + +/** + * Message filter expression type. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public enum ExpressionType { + + SQL92, + + TAG +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/Future.java b/openmessaging-api/src/main/java/io/openmessaging/api/Future.java similarity index 98% rename from openmessaging-api/src/main/java/io/openmessaging/Future.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Future.java index e0973549..a04dc520 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Future.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Future.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; /** *

@@ -28,8 +28,8 @@ * The reason for adding this future is mainly to satisfy the old version of jdk, such as jdk 1.6. *

* - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public interface Future { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/FutureListener.java b/openmessaging-api/src/main/java/io/openmessaging/api/FutureListener.java similarity index 87% rename from openmessaging-api/src/main/java/io/openmessaging/FutureListener.java rename to openmessaging-api/src/main/java/io/openmessaging/api/FutureListener.java index 866d7449..06010cfa 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/FutureListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/FutureListener.java @@ -15,20 +15,20 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; /** * A listener that is called back when a Promise is done. * {@code FutureListener} instances are attached to {@link Future} by passing * them in to {@link Future#addListener(FutureListener)}. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public interface FutureListener { /** - * Invoked when the operation completes, be the associated {@link Promise} successful or not. + * Invoked when the operation completes, successful or not. * @param future The associated promise facade */ void operationComplete(Future future); diff --git a/openmessaging-api/src/main/java/io/openmessaging/ServiceLifecycle.java b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java similarity index 55% rename from openmessaging-api/src/main/java/io/openmessaging/ServiceLifecycle.java rename to openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java index 3066cd56..8b562d8f 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/ServiceLifecycle.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java @@ -8,32 +8,41 @@ * * 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. + * 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; - -import io.openmessaging.consumer.Consumer; -import io.openmessaging.extension.Extension; -import io.openmessaging.producer.Producer; +package io.openmessaging.api; /** - * The {@code ServiceLifecycle} defines a lifecycle interface for a OMS related service endpoint, like {@link Producer}, - * {@link Consumer}, and so on. + * The {@code LifeCycle} defines a lifecycle interface for a OMS related service endpoint, like {@link Producer}, {@link + * Consumer}, and so on. *

* If the service endpoint class implements the {@code ServiceLifecycle} interface, most of the containers can manage * the lifecycle of the corresponding service endpoint objects easily. *

* Any service endpoint should support repeated restart if it implements the {@code ServiceLifecycle} interface. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.2.0 + * @since OMS 1.2.0 */ -public interface ServiceLifecycle extends Extension { +public interface LifeCycle { + /** + * Used to determine whether the current instance is started. + * + * @return if this instance has been started success, this method will return true, otherwise false. + */ + boolean isStarted(); + + /** + * Used to determine whether the current instance is closed. + * + * @return if this instance has been stopped, this method will return true, otherwise false. + */ + boolean isClosed(); + /** * Used for startup or initialization of a service endpoint. A service endpoint instance will be in a ready state * after this method has been completed. @@ -44,13 +53,5 @@ public interface ServiceLifecycle extends Extension { * Notify a service instance of the end of its life cycle. Once this method completes, the service endpoint could be * destroyed and eligible for garbage collection. */ - void stop(); - - /** - * Used for get service current state, for execution of some operations is dependent on the current service state. - * - * @return This service current state {@link ServiceLifeState} - */ - ServiceLifeState currentState(); - + void shutdown(); } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Message.java b/openmessaging-api/src/main/java/io/openmessaging/api/Message.java new file mode 100644 index 00000000..ad5d4256 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Message.java @@ -0,0 +1,283 @@ +/* + * 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; + +import java.io.Serializable; +import java.util.Properties; + +/** + * The {@code Message} interface is the root interface of all OMS messages, and the most commonly used OMS message is + * {@link Message}. + *

+ * Most message-oriented middleware (MOM) products treat messages as lightweight entities that consist of header and + * body and is used by separate applications to exchange a piece of information, like Apache RocketMQ. + *

+ * The header contains fields used by the messaging system that describes the message's meta information, while the body + * contains the application data being transmitted. + *

+ * As for the message header, OMS defines two kinds types: userProperties and systemProperties with respect to + * flexibility in vendor implementation and user usage. + *

    + *
  • + * System Properties, OMS defines some standard attributes in {@link SystemPropKey} that represent the characteristics + * of the message. + *
  • + *
  • + * User properties, some OMS vendors may require enhanced extra attributes of the message or some users may want to + * clarify some customized attributes to draw the body. OMS provides the improved scalability for these scenarios. + *
  • + *
+ * The body contains the application data being transmitted, which is generally ignored by the messaging system and + * simply transmitted to its destination. + *

+ * In BytesMessage, the body is just a byte array, may be compressed and uncompressed in the transmitting process by the + * messaging system. The application is responsible for explaining the concrete content and format of the message body, + * OMS is never aware of that. + * + * The body part is placed in the implementation classes of {@code Message}. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public class Message implements Serializable { + + private static final long serialVersionUID = -1385924226856188094L; + + protected Properties systemProperties; + + private String topic; + + private Properties userProperties; + + private byte[] body; + + public Message() { + this(null, null, "", null); + } + + public Message(String topic, String tag, String key, byte[] body) { + this.topic = topic; + this.body = body; + + this.putSystemProperties(SystemPropKey.TAG, tag); + this.putSystemProperties(SystemPropKey.KEY, key); + } + + public void putSystemProperties(final String key, final String value) { + if (null == this.systemProperties) { + this.systemProperties = new Properties(); + } + + if (key != null && value != null) { + this.systemProperties.put(key, value); + } + } + + public Message(String topic, String tags, byte[] body) { + this(topic, tags, "", body); + } + + public void putUserProperties(final String key, final String value) { + if (null == this.userProperties) { + this.userProperties = new Properties(); + } + + if (key != null && value != null) { + this.userProperties.put(key, value); + } + } + + public String getUserProperties(final String key) { + if (null != this.userProperties) { + return (String) this.userProperties.get(key); + } + + return null; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getTag() { + return this.getSystemProperties(SystemPropKey.TAG); + } + + public String getSystemProperties(final String key) { + if (null != this.systemProperties) { + return this.systemProperties.getProperty(key); + } + + return null; + } + + public void setTag(String tag) { + this.putSystemProperties(SystemPropKey.TAG, tag); + } + + public String getKey() { + return this.getSystemProperties(SystemPropKey.KEY); + } + + public void setKey(String key) { + this.putSystemProperties(SystemPropKey.KEY, key); + } + + public String getMsgID() { + return this.getSystemProperties(SystemPropKey.MSGID); + } + + public void setMsgID(String msgid) { + this.putSystemProperties(SystemPropKey.MSGID, msgid); + } + + public Properties getSystemProperties() { + if (null == systemProperties) { + return new Properties(); + } + return systemProperties; + } + + public void setSystemProperties(Properties systemProperties) { + this.systemProperties = systemProperties; + } + + public Properties getUserProperties() { + if (null == userProperties) { + return new Properties(); + } + return userProperties; + } + + public void setUserProperties(Properties userProperties) { + this.userProperties = userProperties; + } + + public byte[] getBody() { + return body; + } + + public void setBody(byte[] body) { + this.body = body; + } + + public int getReconsumeTimes() { + String pro = this.getSystemProperties(SystemPropKey.RECONSUMETIMES); + if (pro != null) { + return Integer.parseInt(pro); + } + + return 0; + } + + public void setReconsumeTimes(final int value) { + putSystemProperties(SystemPropKey.RECONSUMETIMES, String.valueOf(value)); + } + + public long getBornTimestamp() { + String pro = this.getSystemProperties(SystemPropKey.BORNTIMESTAMP); + if (pro != null) { + return Long.parseLong(pro); + } + + return 0L; + } + + public void setBornTimestamp(final long value) { + putSystemProperties(SystemPropKey.BORNTIMESTAMP, String.valueOf(value)); + } + + public String getBornHost() { + String pro = this.getSystemProperties(SystemPropKey.BORNHOST); + return pro == null ? "" : pro; + } + + public void setBornHost(final String value) { + putSystemProperties(SystemPropKey.BORNHOST, value); + } + + public long getStartDeliverTime() { + String pro = this.getSystemProperties(SystemPropKey.STARTDELIVERTIME); + if (pro != null) { + return Long.parseLong(pro); + } + + return 0L; + } + + public String getShardingKey() { + String pro = this.getSystemProperties(SystemPropKey.SHARDINGKEY); + return pro == null ? "" : pro; + } + + public void setShardingKey(final String value) { + putSystemProperties(SystemPropKey.SHARDINGKEY, value); + } + + public void setStartDeliverTime(final long value) { + putSystemProperties(SystemPropKey.STARTDELIVERTIME, String.valueOf(value)); + } + + /** + * Get the offset of this message assigned by the broker. + * + * @return Message offset in relative partition + */ + public long getOffset() { + String v = getSystemProperties(SystemPropKey.CONSUMEOFFSET); + if (v != null) { + return Long.parseLong(v); + } + return 0; + } + + /** + * Get the partition to which the message belongs. + * + * @return Message offset in relative partition + */ + public TopicPartition getTopicPartition() { + return new TopicPartition(topic, getSystemProperties(SystemPropKey.PARTITION)); + } + + @Override + public String toString() { + return "Message [topic=" + topic + ", systemProperties=" + systemProperties + ", userProperties=" + userProperties + ", body=" + + (body != null ? body.length : 0) + "]"; + } + + static public class SystemPropKey { + public static final String TAG = "__TAG"; + public static final String KEY = "__KEY"; + public static final String MSGID = "__MSGID"; + public static final String SHARDINGKEY = "__SHARDINGKEY"; + public static final String RECONSUMETIMES = "__RECONSUMETIMES"; + public static final String BORNTIMESTAMP = "__BORNTIMESTAMP"; + public static final String BORNHOST = "__BORNHOST"; + + public static final String STARTDELIVERTIME = "__STARTDELIVERTIME"; + + public static final String CONSUMEOFFSET = "__CONSUMEOFFSET"; + + public static final String PARTITION = "__PARTITION"; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java new file mode 100644 index 00000000..a20e72b0 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java @@ -0,0 +1,68 @@ +/* + * 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; + +import java.util.Properties; + +/** + * Used for set or get the relevant properties of a message. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public class MessageAccessor { + /** + * Used for get all system properties. + * + * @param msg + * @return system properties + */ + public static Properties getSystemProperties(final Message msg) { + return msg.systemProperties; + } + + /** + * Used for set system properties, will used new systemProperties to override current systemProperties. + * + * @param msg + * @return system properties + */ + public static void setSystemProperties(final Message msg, Properties systemProperties) { + msg.systemProperties = systemProperties; + } + + /** + * Used for set system property for a specified key, will used new value to replace origin system property of a + * specified key. + * + * @param msg + * @return + */ + public static void putSystemProperties(final Message msg, final String key, final String value) { + msg.putSystemProperties(key, value); + } + + /** + * Used for get a system property value for a specified key. + * + * @param msg + * @return system property value of specified key + */ + public static String getSystemProperties(final Message msg, final String key) { + return msg.getSystemProperties(key); + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java new file mode 100644 index 00000000..4cc2b379 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java @@ -0,0 +1,43 @@ +/* + * 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; + +/** + * Message consume listener, registed for consume messages by consumer. + *

+ * + * Thread safe requirements: this interface will be invoked by multi threads, so users should keep thread safe during + * the consume process. + * + *

+ * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface MessageListener { + + /** + * Consumer message interface, implemented by the application, unstable situations such as network jitter may lead + * to message duplication, and services sensitive to repeated messages need to guarantee idempotent. + * + * @param message + * @param context + * @return if current message consumed success, {@link Action#CommitMessage} should be returned, otherwise, {@link + * Action#ReconsumeLater} should be returned, and this message will be delivered again. + */ + Action consume(final Message message, final ConsumeContext context); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/MessageSelector.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessageSelector.java new file mode 100644 index 00000000..37bde240 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageSelector.java @@ -0,0 +1,49 @@ +/* + * 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; + +public class MessageSelector { + + private ExpressionType type; + + private String subExpression; + + public static MessageSelector bySql(String subExpression) { + return new MessageSelector(ExpressionType.SQL92, subExpression); + } + + public static MessageSelector byTag(String subExpression) { + return new MessageSelector(ExpressionType.TAG, subExpression); + } + + private MessageSelector() { + } + + private MessageSelector(ExpressionType type, String subExpression) { + this.type = type; + this.subExpression = subExpression; + } + + public ExpressionType getType() { + return type; + } + + public String getSubExpression() { + return subExpression; + } +} \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/MessagingAccessPoint.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java similarity index 52% rename from openmessaging-api/src/main/java/io/openmessaging/MessagingAccessPoint.java rename to openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java index 80bee1dd..5166d79e 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/MessagingAccessPoint.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java @@ -15,19 +15,14 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; -import io.openmessaging.consumer.Consumer; -import io.openmessaging.consumer.MessageListener; -import io.openmessaging.consumer.PullConsumer; -import io.openmessaging.consumer.PushConsumer; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.manager.ResourceManager; -import io.openmessaging.message.MessageFactory; -import io.openmessaging.producer.Producer; -import io.openmessaging.producer.TransactionStateCheckListener; -import java.util.Collection; +import io.openmessaging.api.batch.BatchConsumer; +import io.openmessaging.api.order.OrderConsumer; +import io.openmessaging.api.order.OrderProducer; +import io.openmessaging.api.transaction.LocalTransactionChecker; +import io.openmessaging.api.transaction.TransactionProducer; +import java.util.Properties; /** * An instance of {@code MessagingAccessPoint} may be obtained from {@link OMS}, which is capable of creating {@code @@ -39,11 +34,10 @@ * messagingAccessPoint.startup(); * Producer producer = messagingAccessPoint.createProducer(); * producer.startup(); - * producer.send(producer.createBytesMessage("HELLO_QUEUE", "HELLO_BODY".getBytes(Charset.forName("UTF-8")))); * * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public interface MessagingAccessPoint { @@ -60,16 +54,15 @@ public interface MessagingAccessPoint { *

* There are some standard attributes defined by OMS for {@code MessagingAccessPoint}: *

    - *
  • {@link OMSBuiltinKeys#ACCESS_POINTS}, the specified access points. + *
  • {@link OMSBuiltinKeys#ENDPOINT}, the specified access points. *
  • {@link OMSBuiltinKeys#DRIVER_IMPL}, the fully qualified class name of the specified MessagingAccessPoint's * implementation, the default value is {@literal io.openmessaging..MessagingAccessPointImpl}. *
  • {@link OMSBuiltinKeys#REGION}, the region the resources reside in. - *
  • {@link OMSBuiltinKeys#ACCOUNT_ID}, the ID of the specific account system that owns the resource. *
* * @return the attributes */ - KeyValue attributes(); + Properties attributes(); /** * Creates a new {@code Producer} for the specified {@code MessagingAccessPoint}. @@ -79,75 +72,66 @@ public interface MessagingAccessPoint { * error * @throws OMSSecurityException if have no authority to create a producer. */ - Producer createProducer(); + Producer createProducer(final Properties properties); /** - * Creates a new transactional {@code Producer} for the specified {@code MessagingAccessPoint}, the producer is able - * to respond to requests from the server to check the status of the transaction. + * Creates a new {@code OrderProducer} for the specified {@code MessagingAccessPoint}. * - * @param transactionStateCheckListener transactional check listener {@link TransactionStateCheckListener} - * @return the created {@code Producer} + * @return the created {@code OrderProducer} * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request due to some internal * error * @throws OMSSecurityException if have no authority to create a producer. */ - Producer createProducer(TransactionStateCheckListener transactionStateCheckListener); + OrderProducer createOrderProducer(final Properties properties); /** - * Creates a new {@code PushConsumer} for the specified {@code MessagingAccessPoint}. - * The returned {@code PushConsumer} isn't attached to any queue, - * uses {@link PushConsumer#bindQueue(Collection, MessageListener)} to attach queues. + * Creates a new {@code TransactionProducer} for the specified {@code MessagingAccessPoint}. * - * @return the created {@code PushConsumer} - * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request - * due to some internal error - */ - PushConsumer createPushConsumer(); - - /** - * Creates a new {@code PullConsumer} for the specified {@code MessagingAccessPoint}. - * - * @return the created {@code PullConsumer} - * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request - * due to some internal error + * @return the created {@code TransactionProducer} + * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request due to some internal + * error + * @throws OMSSecurityException if have no authority to create a producer. */ - PullConsumer createPullConsumer(); + TransactionProducer createTransactionProducer(final Properties properties, final LocalTransactionChecker checker); /** - * Creates a new {@code PushConsumer} for the specified {@code MessagingAccessPoint} with some preset attributes. + * Creates a new {@code Consumer} for the specified {@code MessagingAccessPoint}. The returned {@code Consumer} + * isn't subscribe any topic, and default Consumer will running with push model. * - * @param attributes the preset attributes - * @return the created {@code PushConsumer} - * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request - * due to some internal error + * @return the created {@code Consumer} + * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request due to some internal + * error */ - PushConsumer createPushConsumer(KeyValue attributes); + Consumer createConsumer(final Properties properties); /** - * Creates a new {@code PullConsumer} for the specified {@code MessagingAccessPoint}. + * Creates a new {@code PullConsumer} for the specified {@code MessagingAccessPoint}. The returned {@code Consumer} + * isn't subscribe any topic. * * @return the created {@code PullConsumer} - * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request - * due to some internal error + * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request due to some internal + * error */ - PullConsumer createPullConsumer(KeyValue attributes); + PullConsumer createPullConsumer(final Properties properties); + /** - * Gets a lightweight {@code ResourceManager} instance from the specified {@code MessagingAccessPoint}. + * Creates a new {@code BatchConsumer} for the specified {@code MessagingAccessPoint}. The returned {@code Consumer} + * isn't subscribe any topic. * - * @return the resource manger + * @return the created {@code BatchConsumer} * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request due to some internal * error - * @throws OMSSecurityException if have no authority to obtain a resource manager. */ - ResourceManager resourceManager(); + BatchConsumer createBatchConsumer(final Properties properties); /** - * Gets a {@link MessageFactory} instance from the specified {@code MessagingAccessPoint}. + * Creates a new {@code OrderConsumer} for the specified {@code MessagingAccessPoint}. The returned {@code Consumer} + * isn't subscribe any topic. * - * @return the resource manger + * @return the created {@code OrderConsumer} * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request due to some internal * error */ - MessageFactory messageFactory(); + OrderConsumer createOrderedConsumer(final Properties properties); } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java new file mode 100644 index 00000000..908b1ed8 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java @@ -0,0 +1,173 @@ +/* + * 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; + +import io.openmessaging.api.internal.MessagingAccessPointAdapter; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +/** + *

+ * The oms class provides some static methods to create a {@code MessagingAccessPoint} from the specified OMS driver url + * and some useful util methods. + *

+ * + *

+ * The brackets indicate that the extra access points are optional, and a correct OMS driver url needs at least one + * access point, which consists of hostname and port, like localhost:8081. + *

+ * + * @version OMS 1.2.0 + * @since OMS 1.1.0 + */ +public final class OMS { + + private final Properties properties = new Properties(); + + public static OMS builder() { + return new OMS(); + } + + /** + * Set the endpoint provided by messaging vendor. + * + * @param endpoint + * @return + */ + public OMS endpoint(String endpoint) { + this.properties.put(OMSBuiltinKeys.ENDPOINT, endpoint); + return this; + } + + /** + * Set the region provided by messaging vendor. + * + * @param region + * @return + */ + public OMS region(String region) { + this.properties.put(OMSBuiltinKeys.REGION, region); + return this; + } + + /** + *

+ * Set the the driver type of the specified MessagingAccessPoint's * implementation, the default value is {@literal + * io.openmessaging..MessagingAccessPointImpl}. + *

+ * + *

+ * But if the {@link OMS#driverImpl(String)} attribute was set, this attribute will be ignored. + *

+ * + * @param driver + * @return + */ + public OMS driver(String driver) { + this.properties.put(OMSBuiltinKeys.DRIVER, driver); + return this; + } + + /** + *

+ * Set the the fully qualified class name of the specified MessagingAccessPoint's * implementation, the default + * value is {@literal io.openmessaging..MessagingAccessPointImpl}. + *

+ * + *

+ * If this attribute was set, {@link OMS#driver(String)} will be ignored. + *

+ * + * @param driverImpl + * @return + */ + public OMS driverImpl(String driverImpl) { + this.properties.put(OMSBuiltinKeys.DRIVER_IMPL, driverImpl); + return this; + } + + /** + *

+ * Set credentials used by the client. + *

+ * + * @param credentials provided by vendors. + * @return + */ + public OMS withCredentials(Properties credentials) { + if (credentials.getProperty(OMSBuiltinKeys.ACCESS_KEY) != null) { + this.properties.put(OMSBuiltinKeys.ACCESS_KEY, credentials.getProperty(OMSBuiltinKeys.ACCESS_KEY)); + } + if (credentials.getProperty(OMSBuiltinKeys.SECRET_KEY) != null) { + this.properties.put(OMSBuiltinKeys.SECRET_KEY, credentials.getProperty(OMSBuiltinKeys.SECRET_KEY)); + } + if (credentials.getProperty(OMSBuiltinKeys.SECURITY_TOKEN) != null) { + this.properties.put(OMSBuiltinKeys.SECURITY_TOKEN, credentials.getProperty(OMSBuiltinKeys.SECURITY_TOKEN)); + } + return this; + } + + public MessagingAccessPoint build() { + return MessagingAccessPointAdapter.getMessagingAccessPoint(this.properties); + } + + /** + * Set extra custom configs. + * + * @param config extra configs + * @return + */ + public MessagingAccessPoint build(Properties config) { + Set> entrySet = config.entrySet(); + for (Map.Entry entry : entrySet) { + if (!this.properties.containsKey(entry.getKey())) { + this.properties.put(entry.getKey(), entry.getValue()); + } + } + return MessagingAccessPointAdapter.getMessagingAccessPoint(this.properties); + } + + /** + * The version format is X.Y.Z (Major.Minor.Patch), a pre-release version may be denoted by appending a hyphen and a + * series of dot-separated identifiers immediately following the patch version, like X.Y.Z-alpha. + * + *

+ * OMS version follows semver scheme partially. + * + * @see http://semver.org + */ + public static String specVersion = "UnKnown"; + + static { + InputStream stream = OMS.class.getClassLoader().getResourceAsStream("oms.spec.properties"); + try { + if (stream != null) { + Properties properties = new Properties(); + properties.load(stream); + specVersion = String.valueOf(properties.get("version")); + } + } catch (IOException ignore) { + } + } + + private OMS() { + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java similarity index 55% rename from openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java rename to openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java index 7d47d9a6..5fbf3809 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java @@ -15,39 +15,49 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; /** * This is the centralized source for keys that are used for OMS standard attributes. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public interface OMSBuiltinKeys { /** - * The {@code DRIVER_IMPL} key represents the vendor implementation - * entry of {@link MessagingAccessPoint}. + * The {@code DRIVER_IMPL} key represents the vendor implementation entry of {@link MessagingAccessPoint}. */ - String DRIVER_IMPL = "DRIVER_IMPL"; + String DRIVER_IMPL = "driverImpl"; /** - * The {@code ACCESS_POINTS} key shows the specified access points in OMS driver schema. - * @see Access Point Schema + * The {@code ACCESS_KEY} key shows the specified access key in OMS driver schema. */ - String ACCESS_POINTS = "ACCESS_POINTS"; + String ACCESS_KEY = "accessKey"; /** - * The {@code ACCOUNT_ID} key shows the specified account info in OMS driver schema. + * The {@code SECRET_KEY} key shows the specified secret key in OMS attribute. */ - String ACCOUNT_ID = "ACCOUNT_ID"; + String SECRET_KEY = "secretKey"; /** - * The {@code ACCOUNT_KEY} key shows the specified account key in OMS attribute. + * The {@code SECURITY_TOKEN} key shows the specified security token in OMS attribute. */ - String ACCOUNT_KEY = "ACCOUNT_KEY"; + String SECURITY_TOKEN = "securityToken"; /** * The {@code REGION} key shows the specified region in OMS driver schema. */ - String REGION = "REGION"; + String REGION = "region"; + + /** + * The {@code ENDPOINT} key shows the specified host in OMS attribute. + */ + String ENDPOINT = "endpoint"; + + /** + * The {@code DRIVER} key represents the vendor type of {@link MessagingAccessPoint}, but if {@code DRIVER_IMPL} is + * not empty, this {@code DRIVER} value will be ignored. + */ + String DRIVER = "driver"; + } diff --git a/openmessaging-api/src/main/java/io/openmessaging/OMSResponseStatus.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMSResponseStatus.java similarity index 98% rename from openmessaging-api/src/main/java/io/openmessaging/OMSResponseStatus.java rename to openmessaging-api/src/main/java/io/openmessaging/api/OMSResponseStatus.java index cdca2b55..f658b0dc 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMSResponseStatus.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMSResponseStatus.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; -import io.openmessaging.exception.OMSRuntimeException; +import io.openmessaging.api.exception.OMSRuntimeException; /** * This class defined OpenMessaging response status code: diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java new file mode 100644 index 00000000..44dbd57f --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java @@ -0,0 +1,63 @@ +/* + * 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; + +import io.openmessaging.api.exception.OMSRuntimeException; + +/** + * Exception context when a message send failed. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public class OnExceptionContext { + + private String messageId; + + private String topic; + + /** + * Detailed exception stack information. + */ + private OMSRuntimeException exception; + + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + + public OMSRuntimeException getException() { + return exception; + } + + public void setException(OMSRuntimeException exception) { + this.exception = exception; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java new file mode 100644 index 00000000..76573660 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java @@ -0,0 +1,86 @@ +/* + * 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; + +import io.openmessaging.api.exception.OMSDestinationException; +import io.openmessaging.api.exception.OMSMessageFormatException; +import io.openmessaging.api.exception.OMSRuntimeException; +import io.openmessaging.api.exception.OMSSecurityException; +import io.openmessaging.api.exception.OMSTimeOutException; +import java.util.Properties; +import java.util.concurrent.ExecutorService; + +/** + * A {@code Producer} is a simple object used to send messages on behalf of a {@code MessagingAccessPoint}. An instance + * of {@code Producer} is created by calling the {@link MessagingAccessPoint#createProducer(Properties)} method. + *

+ * It provides various {@code send} methods to send a message to a specified destination, which is a {@code Queue} in + * OMS. + *

+ * {@link Producer#send(Message)} means send a message to the destination synchronously, the calling thread will block + * until the send request complete. + *

+ * {@link Producer#sendAsync(Message, SendCallback)} means send a message to the destination asynchronously, the calling thread won't + * block and will return immediately. Since the send call is asynchronous it returns a {@link Future} for the send + * result. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface Producer extends Admin { + + /** + * Sends a message to the specified destination synchronously, the destination should be preset to {@link + * Message#setTopic(String)}, other header fields as well. + * + * @param message a message will be sent. + * @return the successful {@code SendResult}. + * @throws OMSSecurityException when have no authority to send messages to a given destination. + * @throws OMSMessageFormatException when an invalid message is specified. + * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. + * @throws OMSDestinationException when have no given destination in the server. + * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. + */ + SendResult send(final Message message); + + /** + *

+ * There is no {@code Promise} related or {@code RuntimeException} thrown. The calling thread doesn't care about the + * send result and also have no context to get the result. + * + * @param message a message will be sent. + */ + void sendOneway(final Message message); + + /** + * Sends a message to the specified destination asynchronously, the destination should be preset to {@link + * Message#setTopic(String)}, other header fields as well. + *

+ * The returned {@code Promise} will have the result once the operation completes, and the registered {@link + * SendCallback} will be invoked, either because the operation was successful or because of an error. + * + * @param message a message will be sent. + * @param sendCallback {@link SendCallback} + */ + void sendAsync(final Message message, final SendCallback sendCallback); + + /** + * Set call back excutor + * @param callbackExecutor + */ + void setCallbackExecutor(final ExecutorService callbackExecutor); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java new file mode 100644 index 00000000..e01cc8cd --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java @@ -0,0 +1,142 @@ +/* + * 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; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +public interface PullConsumer extends Admin { + + interface TopicPartitionChangeListener { + /** + * This method will be invoked in the condition of partition numbers changed, These scenarios occur when the + * topic is expanded or shrunk. + * + * @param topicPartitions + */ + void onChanged(Set topicPartitions); + } + + /** + * Get metadata about the partitions for a given topic. This method will issue a remote call to the server if it + * does not already have any metadata about the given topic. + * + * @param topic + * @return + */ + Set topicPartitions(String topic); + + /** + * Manually assign a list of partitions to this consumer. This interface does not allow for incremental assignment + * and will replace the previous assignment (if there is one). + * + * If auto-commit is enabled, an async commit (based on the old assignment) will be triggered before the new + * assignment replaces the old one. + * + * @param topicPartitions + */ + void assign(Collection topicPartitions); + + /** + * Register a callback for sensing topic metadata changes. + * + * @param topic + * @param callback + */ + void registerTopicPartitionChangedListener(String topic, TopicPartitionChangeListener callback); + + /** + * Fetch data for the topics or partitions specified using assign API. It is an error to not have subscribed to any + * topics or partitions before polling for data. + * + * @param timeout in millisecond + * @return + */ + List poll(long timeout); + + /** + * Overrides the fetch offsets that the consumer will use on the next {@link #poll(long)} }. If this API is invoked + * for the same message queue more than once, the latest offset will be used on the next poll(). Note that you may + * lose data if this API is arbitrarily used in the middle of consumption. + * + * @param topicPartition + * @param offset + */ + void seek(TopicPartition topicPartition, long offset); + + /** + * Overrides the fetch offsets with the beginning offset in server that the consumer will use on the next {@link + * #poll(long)} }. + * + * @param topicPartition + */ + void seekToBeginning(TopicPartition topicPartition); + + /** + * Overrides the fetch offsets with the end offset in server that the consumer will use on the next {@link + * #poll(long)} }. + * + * @param topicPartition + */ + void seekToEnd(TopicPartition topicPartition); + + /** + * Suspend fetching from the requested message queues. Future calls to {@link #poll(long)} will not return any + * records from these message queues until they have been resumed using {@link #resume(Collection)}. + * + * Note that this method does not affect message queue subscription. In particular, it does not cause a group + * rebalance. + * + * @param topicPartitions + */ + void pause(Collection topicPartitions); + + /** + * Resume specified message queues which have been paused with {@link #pause(Collection)}. New calls to {@link + * #poll(long)} will return records from these partitions if there are any to be fetched. If the message queues were + * not previously paused, this method is a no-op. + * + * @param topicPartitions + */ + void resume(Collection topicPartitions); + + /** + * Look up the offsets for the given message queue by timestamp. The returned offset for each message queue is the + * earliest offset whose timestamp is greater than or equal to the given timestamp in the corresponding message + * queue. + * + * @param topicPartition + * @param timestamp + * @return + */ + Long offsetForTimestamp(TopicPartition topicPartition, Long timestamp); + + /** + * Get the last committed offset for the given message queue (whether the commit happened by this process or + * another). This offset will be used as the position for the consumer in the event of a failure. + * + * @param topicPartition + * @return + */ + Long committed(TopicPartition topicPartition); + + /** + * Sync commit current consumed offset to server. + */ + void commitSync(); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/Client.java b/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java similarity index 56% rename from openmessaging-api/src/main/java/io/openmessaging/Client.java rename to openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java index ed20ebad..e9c0b2c1 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Client.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java @@ -14,28 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; - -import io.openmessaging.extension.Extension; -import java.util.Optional; +package io.openmessaging.api; /** - *

- * A {@code Client} interface contains all the common behaviors of producer and consumer. which can be used to achieve - * some basic interaction with the server. - *

+ * Call back interface used in {@link Producer#sendAsync(Message, SendCallback)}. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.2.0 + * @since OMS 1.2.0 */ -public interface Client { +public interface SendCallback { + + /** + * When message send success, this method will be invoked. + * + * @param sendResult send message result. + * @see SendResult + */ + void onSuccess(final SendResult sendResult); + /** - * Get the extension method, and this interface is optional, Therefore, users need to check whether this interface - * has been implemented by vendors. - *

+ * When message send failed, this method will be invoked. * - * @return the implementation of {@link Extension} + * @param context send message exception context. + * @see OnExceptionContext */ - @io.openmessaging.annotation.Optional - Optional getExtension(); + void onException(final OnExceptionContext context); } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java b/openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java new file mode 100644 index 00000000..e8a030c6 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java @@ -0,0 +1,51 @@ +/* + * 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; + +/** + * Send message result. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public class SendResult { + + private String messageId; + + private String topic; + + public String getMessageId() { + return messageId; + } + + public void setMessageId(String messageId) { + this.messageId = messageId; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + @Override + public String toString() { + return "SendResult[topic=" + topic + ", messageId=" + messageId + ']'; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java new file mode 100644 index 00000000..bb2358ff --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java @@ -0,0 +1,90 @@ +/* + * 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; + +/** + * Used for describe a topic + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public class TopicPartition { + private String topic; + + private String partition; + + public TopicPartition(String topic, String partition) { + this.topic = topic; + this.partition = partition; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getPartition() { + return partition; + } + + public void setPartition(String partition) { + this.partition = partition; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((topic == null) ? 0 : topic.hashCode()); + result = prime * result + ((partition == null) ? 0 : partition.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TopicPartition other = (TopicPartition) obj; + if (partition == null) { + if (other.partition != null) { + return false; + } + } else if (!partition.equals(other.partition)) { + return false; + } + if (topic == null) { + if (other.topic != null) + return false; + } else if (!topic.equals(other.topic)) { + return false; + } + return true; + } + + @Override public String toString() { + return "TopicPartition{" + + "topic='" + topic + '\'' + + ", partition='" + partition + '\'' + + '}'; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java new file mode 100644 index 00000000..0d624d81 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java @@ -0,0 +1,47 @@ +/* + * 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.batch; + +import io.openmessaging.api.Admin; + +/** + * Batch message consumer, used to subscribe to messages in batch. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface BatchConsumer extends Admin { + + /** + * Subscribe message + * + * @param topic + * @param subExpression Subscribe to the filter expression string, which the broker filters based on this + * expression.
eg: "tag1 || tag2 || tag3"
, if subExpression is equal to null or *, it means subscribe all + * messages. + * @param listener consume message callback listener. + */ + void subscribe(final String topic, final String subExpression, final BatchMessageListener listener); + + /** + * Unsubscribe topic + * + * @param topic + */ + void unsubscribe(final String topic); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java new file mode 100644 index 00000000..45e62cae --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java @@ -0,0 +1,42 @@ +/* + * 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.batch; + +import io.openmessaging.api.Action; +import io.openmessaging.api.ConsumeContext; +import io.openmessaging.api.Message; +import java.util.List; + +/** + * Batch message listener. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface BatchMessageListener { + + /** + * When message arrived, this method will be invoked by order. + * + * @param messages received message + * @param context + * @return {@link Action} if this message consumed success, {@link Action#CommitMessage} should be returned, + * otherwise return {@link Action#ReconsumeLater} + */ + Action consume(final List messages, final ConsumeContext context); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java b/openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java new file mode 100644 index 00000000..4b0787d2 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java @@ -0,0 +1,97 @@ +/* + * 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.bean; + +import io.openmessaging.api.ExpressionType; + +/** + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public class Subscription { + private String topic; + private String expression; + + /** + * TAG or SQL92 + *
if null, equals to TAG + * + * @see ExpressionType#TAG + * @see ExpressionType#SQL92 + */ + private String type; + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public String getExpression() { + return expression; + } + + public void setExpression(String expression) { + this.expression = expression; + } + + public String getType() { + return type; + } + + public void setType(final String type) { + this.type = type; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((topic == null) ? 0 : topic.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Subscription other = (Subscription) obj; + if (topic == null) { + if (other.topic != null) { + return false; + } + } else if (!topic.equals(other.topic)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Subscription [topic=" + topic + ", expression=" + expression + ", type=" + type + "]"; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java b/openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java new file mode 100644 index 00000000..e50b1a47 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java @@ -0,0 +1,50 @@ +/* + * 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.bean; + +/** + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public class SubscriptionExt extends Subscription { + private boolean persistence = true; + + public boolean isPersistence() { + return persistence; + } + + public void setPersistence(boolean persistence) { + this.persistence = persistence; + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + + @Override + public String toString() { + return "Subscription [topic=" + super.getTopic() + ", expression=" + super.getExpression() + + ", persistence=" + persistence + "]"; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSDestinationException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSDestinationException.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/exception/OMSDestinationException.java rename to openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSDestinationException.java index 495876de..a3f1667c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSDestinationException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSDestinationException.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; /** * The {@code OMSDestinationException} must be thrown when the specified destination does not exist or the destination * is not readable or writable * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class OMSDestinationException extends OMSRuntimeException { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSMessageFormatException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSMessageFormatException.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/exception/OMSMessageFormatException.java rename to openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSMessageFormatException.java index 69c47835..a53f6401 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSMessageFormatException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSMessageFormatException.java @@ -15,14 +15,14 @@ * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; /** * The {@code OMSMessageFormatException} must be thrown when the provided message is not supported or the attributes are * the wrong type. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class OMSMessageFormatException extends OMSRuntimeException { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSRuntimeException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSRuntimeException.java similarity index 76% rename from openmessaging-api/src/main/java/io/openmessaging/exception/OMSRuntimeException.java rename to openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSRuntimeException.java index 9578786d..2445668d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSRuntimeException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSRuntimeException.java @@ -15,7 +15,9 @@ * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; + +import io.openmessaging.api.OMSResponseStatus; /** * This is the root class of all unchecked exceptions in the OMS API. @@ -26,20 +28,38 @@ *

  • A provider-specific string error code to identify the specific exception type.
  • * * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class OMSRuntimeException extends RuntimeException { /** * Vendor-specific error code + * * @see Error **/ - private final int errorCode; + private int errorCode; + + public OMSRuntimeException() { + } + + public OMSRuntimeException(String message) { + super(message); + this.errorCode = OMSResponseStatus.STATUS_1400.getStatusCode(); + } + + public OMSRuntimeException(Throwable cause) { + super(cause); + this.errorCode = OMSResponseStatus.STATUS_1400.getStatusCode(); + } + + public OMSRuntimeException(String message, Throwable cause) { + super(message, cause); + this.errorCode = OMSResponseStatus.STATUS_1400.getStatusCode(); + } /** - * Constructs a {@code OMSRuntimeException} with the specified detail message - * and error code. + * Constructs a {@code OMSRuntimeException} with the specified detail message and error code. * * @param errorCode a specified error code * @param message a description of the exception @@ -61,8 +81,7 @@ public OMSRuntimeException(int errorCode, Throwable cause) { } /** - * Constructs a {@code OMSRuntimeException} with the specified detail message, - * error code and cause. + * Constructs a {@code OMSRuntimeException} with the specified detail message, error code and cause. * * @param errorCode a specified error code * @param message a description of the exception diff --git a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSSecurityException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSSecurityException.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/exception/OMSSecurityException.java rename to openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSSecurityException.java index 2480399e..574ca89c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSSecurityException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSSecurityException.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; /** * The {@code OMSSecurityException} must be thrown when the client have no enough authority to operate an resource. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class OMSSecurityException extends OMSRuntimeException { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTimeOutException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSTimeOutException.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/exception/OMSTimeOutException.java rename to openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSTimeOutException.java index 05555897..3d5a62e9 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTimeOutException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSTimeOutException.java @@ -15,15 +15,15 @@ * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; /** * The {@code OMSTimeOutException} must be thrown when a blocking operation times out. *

    * Blocking operations for which a timeout is specified need a means to indicate that the timeout has occurred. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class OMSTimeOutException extends OMSRuntimeException { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTransactionException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSTransactionException.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/exception/OMSTransactionException.java rename to openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSTransactionException.java index 07523790..8caedeea 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTransactionException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSTransactionException.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; /** * The {@code OMSTransactionException} must be thrown when the client execute a transaction error. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class OMSTransactionException extends OMSRuntimeException { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSUnsupportException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSUnsupportException.java similarity index 88% rename from openmessaging-api/src/main/java/io/openmessaging/exception/OMSUnsupportException.java rename to openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSUnsupportException.java index 5720d452..67be690f 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSUnsupportException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSUnsupportException.java @@ -14,16 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; -import io.openmessaging.annotation.Optional; /** * The {@code OMSUnsupportException} must be thrown when the specified methods, headers or properties have not been - * provided by vendors, these methods or headers are usually marked by {@link Optional}. + * provided by vendors. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class OMSUnsupportException extends OMSRuntimeException { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/internal/MessagingAccessPointAdapter.java b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java similarity index 53% rename from openmessaging-api/src/main/java/io/openmessaging/internal/MessagingAccessPointAdapter.java rename to openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java index ad68dcbf..509e492a 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/MessagingAccessPointAdapter.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java @@ -15,71 +15,52 @@ * limitations under the License. */ -package io.openmessaging.internal; +package io.openmessaging.api.internal; -import io.openmessaging.KeyValue; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.OMSBuiltinKeys; -import io.openmessaging.OMSResponseStatus; -import io.openmessaging.exception.OMSRuntimeException; +import io.openmessaging.api.MessagingAccessPoint; +import io.openmessaging.api.OMSBuiltinKeys; +import io.openmessaging.api.OMSResponseStatus; +import io.openmessaging.api.exception.OMSRuntimeException; import java.lang.reflect.Constructor; +import java.util.Properties; -import static io.openmessaging.OMSResponseStatus.generateException; +import static io.openmessaging.api.OMSResponseStatus.generateException; /** * The {@code MessagingAccessPointAdapter} provides a common implementation to create a specified {@code * MessagingAccessPoint} instance, used by OMS internally. * - * @version OMS 1.0.0 - * @since OMS 1.0.0 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public class MessagingAccessPointAdapter { /** * Returns a {@code MessagingAccessPoint} instance from the specified OMS driver URL with some preset userHeaders. * - * @param url the driver URL. * @param attributes the preset userHeaders. * @return a {@code MessagingAccessPoint} instance. * @throws OMSRuntimeException if the adapter fails to create a {@code MessagingAccessPoint} instance from the URL. */ - public static MessagingAccessPoint getMessagingAccessPoint(String url, KeyValue attributes) { - AccessPointURI accessPointURI = new AccessPointURI(url); - String driverImpl = parseDriverImpl(accessPointURI.getDriverType(), attributes); + public static MessagingAccessPoint getMessagingAccessPoint(Properties attributes) { + String driverImpl = parseDriverImpl(attributes.getProperty(OMSBuiltinKeys.DRIVER), attributes); - attributes.put(OMSBuiltinKeys.ACCESS_POINTS, accessPointURI.getHosts()); attributes.put(OMSBuiltinKeys.DRIVER_IMPL, driverImpl); - attributes.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion()); - attributes.put(OMSBuiltinKeys.ACCOUNT_ID, accessPointURI.getAccountId()); try { Class driverImplClass = Class.forName(driverImpl); - Constructor constructor = driverImplClass.getConstructor(KeyValue.class); + Constructor constructor = driverImplClass.getConstructor(Properties.class); MessagingAccessPoint vendorImpl = (MessagingAccessPoint) constructor.newInstance(attributes); - checkSpecVersion(OMS.specVersion, vendorImpl.version()); return vendorImpl; } catch (Throwable e) { - throw generateException(OMSResponseStatus.STATUS_10000, url); + throw generateException(OMSResponseStatus.STATUS_10000); } } - private static String parseDriverImpl(String driverType, KeyValue attributes) { + private static String parseDriverImpl(String driverType, Properties attributes) { if (attributes.containsKey(OMSBuiltinKeys.DRIVER_IMPL)) { - return attributes.getString(OMSBuiltinKeys.DRIVER_IMPL); + return attributes.getProperty(OMSBuiltinKeys.DRIVER_IMPL); } return "io.openmessaging." + driverType + ".MessagingAccessPointImpl"; } - private static void checkSpecVersion(final String specVersion, final String implVersion) { - String majorVerOfImpl; - String majorVerOfSpec = specVersion.substring(0, specVersion.indexOf('.', specVersion.indexOf('.') + 1)); - try { - majorVerOfImpl = implVersion.substring(0, implVersion.indexOf('.', implVersion.indexOf('.') + 1)); - } catch (Throwable e) { - throw generateException(OMSResponseStatus.STATUS_10002, implVersion); - } - if (!majorVerOfSpec.equals(majorVerOfImpl)) { - throw generateException(OMSResponseStatus.STATUS_10003, implVersion, specVersion); - } - } } \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/order/ConsumeOrderContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/ConsumeOrderContext.java new file mode 100644 index 00000000..fe4884d3 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/ConsumeOrderContext.java @@ -0,0 +1,21 @@ +/* + * 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.order; + +public class ConsumeOrderContext { + +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java new file mode 100644 index 00000000..9f93293c --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java @@ -0,0 +1,40 @@ +/* + * 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.order; + +import io.openmessaging.api.Message; + +/** + * Order message listener, vendors should promise this listener invoked by order, it maybe means vendors should keep + * something thread safe and keep concurrent consume closed. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface MessageOrderListener { + + /** + * When message arrived, this method will be invoked by order. + * + * @param message received message + * @param context + * @return {@link OrderAction} if this message consumed success, {@link OrderAction#Success} should be returned, + * otherwise return {@link OrderAction#Suspend} + */ + OrderAction consume(final Message message, final ConsumeOrderContext context); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.java new file mode 100644 index 00000000..7edafc4d --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.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.order; + +/** + * Order message consumption result. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public enum OrderAction { + + /** + * Consumption is successful, continue to consume the next message. + */ + Success, + + /** + * Consumption failed, suspending the current queue. + */ + Suspend, +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java new file mode 100644 index 00000000..40d80be8 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java @@ -0,0 +1,55 @@ +/* + * 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.order; + +import io.openmessaging.api.Admin; +import io.openmessaging.api.ExpressionType; +import io.openmessaging.api.MessageSelector; + +/** + * Order consumer interface, subscribe and consume message in order. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface OrderConsumer extends Admin { + + /** + * Subscribe message in order. + * + * @param topic message topic. + * @param subExpression Subscribe to the filter expression string, which the broker filters based on this + * expression.
    eg: "tag1 || tag2 || tag3"
    , if subExpression is equal to null or *, it means subscribe all + * messages. + * @param listener The message callback listener, the consumer receives the message and then passes it to the + * message callback listener for consumption. + */ + void subscribe(final String topic, final String subExpression, final MessageOrderListener listener); + + /** + * Subscribe to messages, which can be filtered using SQL expressions. + * + * @param topic + * @param selector Subscribe to the message selector (can be empty, indicating no filtering), the ONS server filters + * according to the expression in this selector. Currently supports two expression syntax: {@link + * ExpressionType#TAG}, {@link ExpressionType#SQL92} Among them, the effect of TAG filtering is consistent with the + * above interface. + * @param listener Message callback listener + */ + void subscribe(final String topic, final MessageSelector selector, final MessageOrderListener listener); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java new file mode 100644 index 00000000..82d8e9b5 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java @@ -0,0 +1,41 @@ +/* + * 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.order; + +import io.openmessaging.api.Admin; +import io.openmessaging.api.Message; +import io.openmessaging.api.SendResult; + +/** + * Sequential message producer interface   + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface OrderProducer extends Admin { + + /** + * Send message in order + * + * @param message + * @param shardingKey Order message selection factor, the sending method selects a specific message queue based on + * shardingKey + * @return {@link SendResult} Message delivery result, including message Id. + */ + SendResult send(final Message message, final String shardingKey); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java new file mode 100644 index 00000000..4cd3eaa8 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java @@ -0,0 +1,38 @@ +/* + * 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.transaction; + +import io.openmessaging.api.Message; + +/** + * Check local transactions, callback by broker. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface LocalTransactionChecker { + + /** + * Check the local transaction, the Broker callback Producer, send the unfinished transaction to the Producer, and + * the Producer will decide again whether the transaction is committed or rolled back.    + * + * @param msg message       + * @return {@link TransactionStatus} Transaction status, including commit transaction, rollback transaction, unknown + * state       + */ + TransactionStatus check(final Message msg); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecuter.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecuter.java new file mode 100644 index 00000000..2ed9cd5d --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecuter.java @@ -0,0 +1,39 @@ +/* + * 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.transaction; + +import io.openmessaging.api.Message; + +/** + * Local transaction executor. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0  + */ +public interface LocalTransactionExecuter { + + /** + * Execute local transactions, rewritten by the application. + * + * @param message + * @param arg Custom parameters, passed in and callback by the send method + * @return {@link TransactionStatus} Returns the result{@link TransactionStatus} of the transaction execution, + * including commit transaction, rollback transaction, unknown state + */ + TransactionStatus execute(final Message message, final Object arg); +} 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 new file mode 100644 index 00000000..99cf519b --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java @@ -0,0 +1,49 @@ +/* + * 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.transaction; + +import io.openmessaging.api.Admin; +import io.openmessaging.api.Message; +import io.openmessaging.api.SendResult; + +/** + * Send transactional message. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public interface TransactionProducer extends Admin { + + /** + * This method is used to send a transactional message. A transactional message is sent in three steps: + *

      + *
    1. The service implementation class first sends a half message to the message server;
    2. + *
    3. Execute local transactions via executer
    4. + *
    5. According to the execution result of the previous step, it is decided to send a commit or roll back the + * semi-message sent by the first step
    6. + *
    + * + * @param message transactional message + * @param localTransactionExecutor local transactional executor + * @param arg Apply a custom parameter that can be passed to the local transaction executor + * @return Send result + */ + SendResult send(final Message message, + final LocalTransactionExecuter localTransactionExecutor, + final Object arg); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java new file mode 100644 index 00000000..dba0d3d3 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java @@ -0,0 +1,33 @@ +/* + * 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.transaction; + +/** + * Transaction status. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ +public enum TransactionStatus { + + CommitTransaction, + + RollbackTransaction, + + Unknow +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/consumer/BatchMessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/consumer/BatchMessageListener.java deleted file mode 100644 index bcf0c838..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/consumer/BatchMessageListener.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.consumer; - -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.message.Message; -import java.util.List; - -/** - * A message listener can implement this {@code BathMessageListener} interface and register itself to a consumer - * instance to asynchronously receive messages. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface BatchMessageListener { - /** - * Callback method to receive incoming messages. - *

    - * A message listener should handle different types of {@code BatchMessage}. - * - * @param batchMessage the received batchMessage. - */ - void onReceived(List batchMessage, Context context); - - interface Context { - /** - * Acknowledges the specified and consumed message, which is related to this {@code MessageContext}. - *

    - * Messages that have been received but not acknowledged may be redelivered. - * - * @throws OMSRuntimeException if the consumer fails to acknowledge the messages due to some internal error. - */ - void success(MessageReceipt... messages); - - /** - * Acknowledges all messages in this batch, which is related to this {@code MessageContext}. - *

    - * - * @throws OMSRuntimeException if the consumer fails to acknowledge the messages due to some internal error. - */ - void ack(); - } -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/consumer/Consumer.java b/openmessaging-api/src/main/java/io/openmessaging/consumer/Consumer.java deleted file mode 100644 index 4ea4ea61..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/consumer/Consumer.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.consumer; - -import io.openmessaging.Client; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.ServiceLifecycle; -import io.openmessaging.exception.OMSDestinationException; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.interceptor.ConsumerInterceptor; -import io.openmessaging.message.Message; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -/** - * A {@code PushConsumer} receives messages from multiple queues, these messages are pushed from MOM server to {@code - * Consumer} client. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface Consumer extends ServiceLifecycle, Client { - - /** - * This method is used to find out the collection of queues bind to {@code Consumer}. - * - * @return the queues this consumer is bind, or null if the consumer is not bind queue. - */ - Set getBindQueues(); - - /** - * Adds a {@code ConsumerInterceptor} instance to this consumer. - * - * @param interceptor an interceptor instance. - */ - void addInterceptor(ConsumerInterceptor interceptor); - - /** - * Removes an interceptor from this consumer. - * - * @param interceptor an interceptor to be removed. - */ - void removeInterceptor(ConsumerInterceptor interceptor); - - /** - * Acknowledges the specified and consumed message with the unique message receipt handle, in the scenario of using - * manual commit. - *

    - * Messages that have been received but not acknowledged may be redelivered. - * - * @param receipt the receipt handle associated with the consumed message. - */ - void ack(MessageReceipt receipt); - -} \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/consumer/MessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/consumer/MessageListener.java deleted file mode 100644 index 81a3fa8e..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/consumer/MessageListener.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.consumer; - -import io.openmessaging.message.Message; -import io.openmessaging.exception.OMSRuntimeException; - -/** - * A message listener must implement this {@code MessageListener} interface and register itself to a consumer instance - * to asynchronously receive messages. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface MessageListener { - /** - * Callback method to receive incoming messages. - *

    - * A message listener should handle different types of {@code Message}. - * - * @param message the received message object. - * @param context the context delivered to the consume thread. - */ - void onReceived(Message message, Context context); - - interface Context { - /** - * Acknowledges the specified and consumed message, which is related to this {@code MessageContext}. - *

    - * Messages that have been received but not acknowledged may be redelivered. - * - * @throws OMSRuntimeException if the consumer fails to acknowledge the messages due to some internal error. - */ - void ack(); - } -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/consumer/MessageReceipt.java b/openmessaging-api/src/main/java/io/openmessaging/consumer/MessageReceipt.java deleted file mode 100644 index 26a75395..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/consumer/MessageReceipt.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.consumer; - -/** - * A {@code MessageReceipt} is a {@code Message} with a {@code Receipt}. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface MessageReceipt { -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/consumer/PullConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/consumer/PullConsumer.java deleted file mode 100755 index 82f7814a..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/consumer/PullConsumer.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.consumer; - -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.annotation.Optional; -import io.openmessaging.exception.OMSDestinationException; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.exception.OMSTimeOutException; -import io.openmessaging.extension.QueueMetaData; -import io.openmessaging.message.Message; -import java.util.Collection; -import java.util.List; - -/** - * A {@code PullConsumer} pulls messages from the specified queue, and supports submit the consume result by - * acknowledgement. - * - * @version OMS 1.0.0 - * @see MessagingAccessPoint#createPullConsumer() - * @since OMS 1.0.0 - */ -public interface PullConsumer extends Consumer { - - /** - * Bind the {@code Consumer} to a collection of queue in pull model, user can use {@link PullConsumer#receive(long)} - * to get messages from a collection of queue. - *

    - * - * @param queueNames a collection of queues. - * @throws OMSSecurityException when have no authority to bind to this queue. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - void bindQueue(Collection queueNames); - - /** - * Unbind the {@code Consumer} from a collection of queues. - *

    - * After the success call, this consumer won't receive new message from the specified queue any more. - * - * @param queueNames a collection of queues. - */ - void unbindQueue(Collection queueNames); - - /** - * Receives the next message from the attached queues of this consumer. - *

    - * This call blocks indefinitely until a message is arrives, the timeout expires, or until this {@code PullConsumer} - * is shut down. - * - * @return the next message received from the attached queues, or null if the consumer is concurrently shut down or - * the timeout expires - * @throws OMSRuntimeException if the consumer fails to pull the next message due to some internal error. - */ - Message receive(); - - /** - * Receives the next message from the bind queues of this consumer in pull model. - *

    - * This call blocks indefinitely until a message is arrives, the timeout expires, or until this {@code PullConsumer} - * is shut down. - * - * @param timeout receive message will blocked at most timeout milliseconds. - * @return the next message received from the bind queues, or null if the consumer is concurrently shut down. - * @throws OMSSecurityException when have no authority to receive messages from this queue. - * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - Message receive(long timeout); - - /** - * Receives the next message from the which bind queue,partition and receiptId of this consumer in pull model. - *

    - * This call blocks indefinitely until a message is arrives, the timeout expires, or until this {@code PullConsumer} - * is shut down. - * - * @param queueName receive message from which queueName in Message Queue. - * @param queueMetaData receive message from which partition in Message Queue. - * @param messageReceipt receive message from which receipt position in Message Queue. - * @param timeout receive message will blocked at most timeout milliseconds. - * @return the next message received from the bind queues, or null if the consumer is concurrently shut down. - * @throws OMSSecurityException when have no authority to receive messages from this queue. - * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - @Optional - Message receive(String queueName, QueueMetaData queueMetaData, MessageReceipt messageReceipt, long timeout); - - /** - * Receive message in asynchronous way. This call doesn't block user's thread, and user's message resolve logic - * should implement in the {@link MessageListener}. - *

    - * - * @param timeout receive messages will blocked at most timeout milliseconds. - * @return the next batch messages received from the bind queues, or null if the consumer is concurrently shut down. - * @throws OMSSecurityException when have no authority to receive messages from this queue. - * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - List batchReceive(long timeout); - - /** - * Receive message in asynchronous way. This call doesn't block user's thread, and user's message resolve logic - * should implement in the {@link MessageListener}. - *

    - * - * @param queueName receive message from which queueName in Message Queue. - * @param queueMetaData receive message from which partition in Message Queue. - * @param messageReceipt receive message from which receipt position in Message Queue. - * @param timeout receive messages will blocked at most timeout milliseconds. - * @return the next batch messages received from the bind queues, or null if the consumer is concurrently shut down. - * @throws OMSSecurityException when have no authority to receive messages from this queue. - * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - @Optional - List batchReceive(String queueName, QueueMetaData queueMetaData, MessageReceipt messageReceipt, - long timeout); - - /** - * Acknowledges the specified and consumed message with the unique message receipt handle. - *

    - * Messages that have been received but not acknowledged may be redelivered. - * - * @param receiptHandle the receipt handle associated with the consumed message - * @throws OMSRuntimeException if the consumer fails to acknowledge the messages due to some internal error. - */ - void ack(MessageReceipt receiptHandle); - -} \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/consumer/PushConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/consumer/PushConsumer.java deleted file mode 100644 index 3eaf5ae6..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/consumer/PushConsumer.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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.consumer; - -import io.openmessaging.KeyValue; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.exception.OMSDestinationException; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.message.Message; -import java.util.Collection; -import java.util.List; - -/** - * A {@code PushConsumer} receives messages from multiple queues, these messages are pushed from - * MOM server to {@code PushConsumer} client. - * - * @version OMS 1.0.0 - * @see MessagingAccessPoint#createPushConsumer() - * @since OMS 1.0.0 - */ -public interface PushConsumer extends Consumer{ - /** - * Resumes the {@code Consumer} in push model after a suspend. - *

    - * This method resumes the {@code Consumer} instance after it was suspended. The instance will not receive new - * messages between the suspend and resume calls. - * - * @throws OMSRuntimeException if the instance has not been suspended. - * @see PushConsumer#suspend() - */ - void resume(); - - /** - * Suspends the {@code Consumer} in push model for later resumption. - *

    - * This method suspends the consumer until it is resumed. The consumer will not receive new messages between the - * suspend and resume calls. - *

    - * This method behaves exactly as if it simply performs the call {@code suspend(0)}. - * - * @throws OMSRuntimeException if the instance is not currently running. - * @see PushConsumer#resume() - */ - void suspend(); - - /** - * Suspends the {@code Consumer} in push model for later resumption. - *

    - * This method suspends the consumer until it is resumed or a specified amount of time has elapsed. The consumer - * will not receive new messages during the suspended state. - *

    - * This method is similar to the {@link #suspend()} method, but it allows finer control over the amount of time to - * suspend, and the consumer will be suspended until it is resumed if the timeout is zero. - * - * @param timeout the maximum time to suspend in milliseconds. - * @throws OMSRuntimeException if the instance is not currently running. - */ - void suspend(long timeout); - - /** - * This method is used to find out whether the {@code Consumer} in push model is suspended. - * - * @return true if this {@code Consumer} is suspended, false otherwise. - */ - boolean isSuspended(); - - /** - * Bind the {@code Consumer} to a collection of queue, with a {@code MessageListener}. - *

    - * {@link MessageListener#onReceived(Message, MessageListener.Context)} will be called when new delivered message is - * coming. - * - * @param queueNames a collection of queues. - * @param listener a specified listener to receive new message. - * @throws OMSSecurityException when have no authority to bind to this queue. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - void bindQueue(Collection queueNames, MessageListener listener); - - - /** - * Bind the {@code Consumer} to a collection of queue, with a {@code BatchMessageListener}. - *

    - * {@link BatchMessageListener#onReceived(List, BatchMessageListener.Context)} will be called when new delivered - * messages is coming. - * - * @param queueNames a collection of queues. - * @param listener a specified listener to receive new messages. - * @throws OMSSecurityException when have no authority to bind to this queue. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - void bindQueue(Collection queueNames, BatchMessageListener listener); - - /** - * Unbind the {@code Consumer} from a collection of queues. - *

    - * After the success call, this consumer won't receive new message from the specified queue any more. - * - * @param queueNames a collection of queues. - */ - void unbindQueue(Collection queueNames); - -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/extension/Extension.java b/openmessaging-api/src/main/java/io/openmessaging/extension/Extension.java deleted file mode 100644 index 56edceb9..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/extension/Extension.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.extension; - -import io.openmessaging.annotation.Optional; -import io.openmessaging.exception.OMSDestinationException; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.exception.OMSTimeOutException; -import java.util.Set; - -/** - *

    - * This interface contains some methods are used for getting configurations related implementation. but this interface - * are not mandatory. - *

    - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -@Optional -public interface Extension { - - /** - * This method used for getting the related queue's meta data, and this method is optional, vendors may not provide - * this method based on their implementation. - *

    - * - * @param queueName Queue name, message destination. - * @return {@link QueueMetaData} Queue config in the server - * @throws OMSSecurityException when have no authority to send messages to a given destination. - * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - Set getQueueMetaData(String queueName); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/extension/ExtensionHeader.java b/openmessaging-api/src/main/java/io/openmessaging/extension/ExtensionHeader.java deleted file mode 100644 index 20e2b32e..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/extension/ExtensionHeader.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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.extension; - -import io.openmessaging.annotation.Optional; -import io.openmessaging.message.Message; - -/** - *

    - * The {@code ExtensionHeader} interface contains extended properties for common implementations in current messaging - * and streaming field, such as the queue-based partitioning implementation, but the related properties in this - * interface are not mandatory. - *

    - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -@Optional -public interface ExtensionHeader { - /** - * The {@code PARTITION} in extension header field contains the partition of target destination which the message - * is being sent. - *

    - * - * When a {@link Message} is set with this value, this message will be delivered to specified partition, but the - * premise is that the implementation of the server side is dependent on the partition or a queue-like storage - * mechanism. - *

    - * - * @param partition The specified partition will be sent to. - */ - ExtensionHeader setPartition(int partition); - - /** - * This method is only called by the server. and {@code OFFSET} represents this message offset in partition. - *

    - * - * @param offset The offset in the current partition, used to quickly get this message in the queue - */ - ExtensionHeader setOffset(long offset); - - /** - * A client can use the {@code CORRELATION_ID} field to link one message with another. A typical use is to link a - * response message with its request message. - */ - ExtensionHeader setCorrelationId(String correlationId); - - /** - * This field {@code TRANSACTION_ID} is used in transactional message, and it can be used to trace a transaction. - *

    - * So the same {@code TRANSACTION_ID} will be appeared not only in prepare message, but also in commit message, and - * consumer received message also contains this field. - */ - ExtensionHeader setTransactionId(String transactionId); - - /** - * The {@code STORE_TIMESTAMP} header field contains the store timestamp of a message in server side. - *

    - * When a message is sent, STORE_TIMESTAMP is ignored. - *

    - * When the send method returns it contains a server-assigned value. - *

    - * This filed is a {@code long} value, measured in milliseconds. - */ - ExtensionHeader setStoreTimestamp(long storeTimestamp); - - /** - * The {@code STORE_HOST} header field contains the store host info of a message in server side. - *

    - * When a message is sent, STORE_HOST is ignored. - *

    - * When the send method returns it contains a server-assigned value. - */ - ExtensionHeader setStoreHost(String storeHost); - - /** - * The {@code messagekey} header field contains the custom key of a message. - *

    - * This key is a customer identifier for a class of messages, and this key may be used for server to hash or - * dispatch messages, or even can use this key to implement order message. - *

    - */ - ExtensionHeader setMessageKey(String messageKey); - - /** - * The {@code TRACE_ID} header field contains the trace ID of a message, which represents a global and unique - * identification, to associate key events in the whole lifecycle of a message, like sent by who, stored at where, - * and received by who. - *

    - * And, the messaging system only plays exchange role in a distributed system in most cases, so the TraceID can be - * used to trace the whole call link with other parts in the whole system. - */ - ExtensionHeader setTraceId(String traceId); - - /** - * The {@code DELAY_TIME} header field contains a number that represents the delayed times in milliseconds. - *

    - * The message will be delivered after delayTime milliseconds starting from {@code BORN_TIMESTAMP} . When this filed - * isn't set explicitly, this means this message should be delivered immediately. - */ - ExtensionHeader setDelayTime(long delayTime); - - /** - * The {@code EXPIRE_TIME} header field contains the expiration time, it represents a time-to-live value. - *

    - * The {@code EXPIRE_TIME} represents a relative valid interval that a message can be delivered in it. If the - * EXPIRE_TIME field is specified as zero, that indicates the message does not expire. - *

    - *

    - * When an undelivered message's expiration time is reached, the message should be destroyed. OMS does not define a - * notification of message expiration. - *

    - */ - ExtensionHeader setExpireTime(long expireTime); - - /** - * This method will return the partition of this message belongs. - *

    - * - * @return The {@code PARTITION} to which the message belongs - */ - int getPartiton(); - - /** - * This method will return the {@code OFFSET} in the partition to which the message belongs to, but the premise is - * that the implementation of the server side is dependent on the partition or a queue-like storage mechanism. - * - * @return The offset of the partition to which the message belongs. - */ - long getOffset(); - - /** - * See {@link ExtensionHeader#setCorrelationId(String)} - * - * @return correlationId - */ - String getCorrelationId(); - - /** - * See {@link ExtensionHeader#setTransactionId(String)} - * - * @return transactionId - */ - String getTransactionId(); - - /** - * See {@link ExtensionHeader#setStoreTimestamp(long)} - * - * @return storeTimestamp - */ - long getStoreTimestamp(); - - /** - * See {@link ExtensionHeader#setStoreHost(String)} - * - * @return storeHost - */ - String getStoreHost(); - - /** - * See {@link ExtensionHeader#setDelayTime(long)} - * - * @return delayTime - */ - long getDelayTime(); - - /** - * See {@link ExtensionHeader#setExpireTime(long)} - * - * @return expireTime - */ - long getExpireTime(); - - /** - * See {@link ExtensionHeader#setMessageKey(String)} - * - * @return messageKey - */ - String getMessageKey(); - - /** - * See {@link ExtensionHeader#setTraceId(String)} - * - * @return traceId - */ - String getTraceId(); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/extension/QueueMetaData.java b/openmessaging-api/src/main/java/io/openmessaging/extension/QueueMetaData.java deleted file mode 100644 index 0a0409b7..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/extension/QueueMetaData.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.extension; - -import io.openmessaging.annotation.Optional; -import java.util.List; -import java.util.Set; - -/** - * This interface {@code QueueMetaData} contains methods are used for getting configurations related some certain - * implementation. but this interface are not mandatory. - *

    - * - * In order to improve performance, in some scenarios where message persistence is required, some message middleware - * will store messages on multiple partitions in multi servers. - *

    - * - * In some scenarios, it is very useful to get the relevant partitions meta data for a queue. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -@Optional -public interface QueueMetaData { - - /** - * Set queueName to this Message Queue. - * @param queueName - */ - void setQueueName(String queueName); - - /** - * Set the specified partition. - * @param partitionId - */ - void setPartitionId(int partitionId); - - /** - * Get partition identifier of target queue. - * - * @return Partition identifier - */ - int partitionId(); - - /** - * Queue name - *

    - * - * @return Queue name. - */ - String queueName(); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/interceptor/ConsumerInterceptor.java b/openmessaging-api/src/main/java/io/openmessaging/interceptor/ConsumerInterceptor.java deleted file mode 100644 index 98aba203..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/interceptor/ConsumerInterceptor.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.interceptor; - -import io.openmessaging.message.Message; -import io.openmessaging.consumer.MessageListener; - -/** - * A {@code ConsumerInterceptor} is used to intercept consume operations of push consumer. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface ConsumerInterceptor { - /** - * Invoked before the invocation of {@link MessageListener#onReceived(Message, MessageListener.Context)}. - * - * @param message the message is actually received. - * @param attributes the extensible attributes delivered to the intercept thread. - */ - void preReceive(Message message, Context attributes); - - /** - * Invoked after the invocation of {@link MessageListener#onReceived(Message, MessageListener.Context)}. - * - * @param message the message is actually received. - * @param attributes the extensible attributes delivered to the intercept thread. - */ - void postReceive(Message message, Context attributes); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/interceptor/Context.java b/openmessaging-api/src/main/java/io/openmessaging/interceptor/Context.java deleted file mode 100644 index 2ec6498b..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/interceptor/Context.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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.interceptor; - -import io.openmessaging.KeyValue; - -/** - * A {@code Context} is used to transfer user's business data in the interceptor. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface Context { - - /** - * Returns the attributes of this {@code Context} instance. - * - * @return the attributes. - */ - KeyValue attributes(); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/interceptor/ProducerInterceptor.java b/openmessaging-api/src/main/java/io/openmessaging/interceptor/ProducerInterceptor.java deleted file mode 100644 index e41f60a0..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/interceptor/ProducerInterceptor.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.interceptor; - -import io.openmessaging.message.Message; - -/** - * A {@code ProducerInterceptor} is used to intercept send operations of producer. - *

    - * The interceptor is able to view or modify the message being transmitted and collect the send record. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface ProducerInterceptor { - /** - * Invoked before the message is actually sent to the network. - *

    - * This allows for modification of the message if necessary. - * - * @param message a message will be sent. - * @param attributes the extensible attributes delivered to the intercept thread. - */ - void preSend(Message message, Context attributes); - - /** - * Invoked immediately after the successful send invocation. - * - * @param message the message is actually sent. - * @param attributes the extensible attributes delivered to the intercept thread. - */ - void postSend(Message message, Context attributes); - -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/internal/AccessPointURI.java b/openmessaging-api/src/main/java/io/openmessaging/internal/AccessPointURI.java deleted file mode 100644 index 52336b91..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/AccessPointURI.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.internal; - -import io.openmessaging.OMSResponseStatus; - -import static io.openmessaging.OMSResponseStatus.generateException; - -/** - * Represents a AccessPoint String. - * The Connection String describes the details to connect a specific OMS service provider. - */ -public class AccessPointURI { - private static final String PREFIX = "oms:"; - - private final String accessPointString; - private final String driverType; - private final String accountId; - private final String hosts; - private final String region; - - /** - * The standard OMS access point schema is: - *

    - * {@literal oms:://[account_id@]host1[:port1][,host2[:port2],...[,hostN[:portN]]]/} - *

    - * - * More details please refer to: - * Access Point Schema - */ - private static final String PATTERN = "^oms:.+://.+/.+$"; - - AccessPointURI(String accessPointString) { - validateAccessPointString(accessPointString); - this.accessPointString = accessPointString; - String unprocessedString = accessPointString.substring(PREFIX.length()); - - // Split out the user OMS driver info - int idx = unprocessedString.indexOf(":"); - this.driverType = unprocessedString.substring(0, idx); - - //Skip '://' - unprocessedString = unprocessedString.substring(driverType.length() + 3); - - idx = unprocessedString.lastIndexOf('/'); - - this.region = unprocessedString.substring(idx + 1); - String userAndHostInformation = unprocessedString.substring(0, idx); - - idx = userAndHostInformation.indexOf('@'); - - if (idx > 0) { - accountId = userAndHostInformation.substring(0, idx); - hosts = userAndHostInformation.substring(idx + 1); - } else { - hosts = userAndHostInformation; - accountId = null; - } - } - - public String getAccessPointString() { - return accessPointString; - } - - public String getDriverType() { - return driverType; - } - - public String getAccountId() { - return accountId; - } - - public String getHosts() { - return hosts; - } - - public String getRegion() { - return region; - } - - private void validateAccessPointString(String accessPointString) { - if (!accessPointString.matches(PATTERN)) { - throw generateException(OMSResponseStatus.STATUS_10001, accessPointString); - } - } -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java b/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java deleted file mode 100644 index 952e17c6..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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.internal; - -import io.openmessaging.KeyValue; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * The default implementation of the interface {@link KeyValue}, used by OMS internally. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public class DefaultKeyValue implements KeyValue { - private Map properties; - - @Override - public KeyValue put(String key, boolean value) { - properties.put(key, String.valueOf(value)); - return this; - } - - @Override - public boolean getBoolean(String key) { - if (!properties.containsKey(key)) { - return false; - } - return Boolean.valueOf(properties.get(key)); - } - - @Override - public boolean getBoolean(String key, boolean defaultValue) { - return properties.containsKey(key) ? getBoolean(key) : defaultValue; - } - - @Override - public short getShort(String key) { - if (!properties.containsKey(key)) { - return 0; - } - return Short.valueOf(properties.get(key)); - } - - @Override - public short getShort(String key, short defaultValue) { - return properties.containsKey(key) ? getShort(key) : defaultValue; - } - - @Override - public KeyValue put(String key, short value) { - properties.put(key, String.valueOf(value)); - return this; - } - - public DefaultKeyValue() { - properties = new ConcurrentHashMap(); - } - - @Override - public KeyValue put(String key, int value) { - properties.put(key, String.valueOf(value)); - return this; - } - - @Override - public KeyValue put(String key, long value) { - properties.put(key, String.valueOf(value)); - return this; - } - - @Override - public KeyValue put(String key, double value) { - properties.put(key, String.valueOf(value)); - return this; - } - - @Override - public KeyValue put(String key, String value) { - properties.put(key, String.valueOf(value)); - return this; - } - - @Override - public int getInt(String key) { - if (!properties.containsKey(key)) { - return 0; - } - return Integer.valueOf(properties.get(key)); - } - - @Override - public int getInt(final String key, final int defaultValue) { - return properties.containsKey(key) ? getInt(key) : defaultValue; - } - - @Override - public long getLong(String key) { - if (!properties.containsKey(key)) { - return 0; - } - return Long.valueOf(properties.get(key)); - } - - @Override - public long getLong(final String key, final long defaultValue) { - return properties.containsKey(key) ? getLong(key) : defaultValue; - } - - @Override - public double getDouble(String key) { - if (!properties.containsKey(key)) { - return 0; - } - return Double.valueOf(properties.get(key)); - } - - @Override - public double getDouble(final String key, final double defaultValue) { - return properties.containsKey(key) ? getDouble(key) : defaultValue; - } - - @Override - public String getString(String key) { - return properties.get(key); - } - - @Override - public String getString(final String key, final String defaultValue) { - return properties.containsKey(key) ? getString(key) : defaultValue; - } - - @Override - public Set keySet() { - return properties.keySet(); - } - - @Override - public boolean containsKey(String key) { - return properties.containsKey(key); - } -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/manager/ResourceManager.java b/openmessaging-api/src/main/java/io/openmessaging/manager/ResourceManager.java deleted file mode 100644 index 6baf0c89..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/manager/ResourceManager.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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.manager; - -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.exception.OMSDestinationException; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.exception.OMSTimeOutException; -import java.util.Set; - -/** - * The {@code ResourceManager} is to provide a unified interface of resource management, allowing developers to manage - * the namespace, queue and routing resources. - *

    - * Create, set, get and delete are the four basic operations of {@code ResourceManager}. - *

    - * {@code ResourceManager} also supports dynamic fetch and update of resource attributes. - *

    - * {@link MessagingAccessPoint#resourceManager()} ()} is the unique method to obtain a {@code ResourceManager} instance. - * Changes made through this instance will immediately apply to the message-oriented middleware (MOM) behind {@code - * MessagingAccessPoint}. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface ResourceManager { - /** - * Creates a {@code Namespace} resource with some preset attributes. - *

    - * A namespace wraps the OMS resources in an abstract concept that makes it appear to the users within the namespace - * that they have their own isolated instance of the global OMS resources. - * - * @param nsName the name of the new namespace. - * @throws OMSSecurityException when have no authority to create namespace. - * @throws OMSTimeOutException when the given timeout elapses before the create operation completes. - * @throws OMSDestinationException when this given destination has been created in the server. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to create namespace due to some internal - * error. - */ - void createNamespace(String nsName); - - /** - * Deletes an existing namespace. - * - * @param nsName the namespace needs to be deleted. - * @throws OMSSecurityException when have no authority to delete this namespace. - * @throws OMSTimeOutException when the given timeout elapses before the delete operation completes. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to delete the namespace due to some internal - * error. - */ - void deleteNamespace(String nsName); - - /** - * Switch to an existing namespace. - * - * @param targetNamespace the namespace needs to be switched. - * @throws OMSSecurityException when have no authority to delete this namespace. - * @throws OMSTimeOutException when the given timeout elapses before the delete operation completes. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to delete the namespace due to some internal - * error. - */ - void switchNamespace(String targetNamespace); - - /** - * Gets the namespace list in the current {@code MessagingAccessPoint}. - * - * @return the set of all namespaces. - * @throws OMSSecurityException when have no authority to delete this namespace. - * @throws OMSTimeOutException when the given timeout elapses before the list operation completes. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to list the namespace due to some internal - * error. - */ - Set listNamespaces(); - - /** - * Creates a {@code Queue} resource in the configured namespace with some preset attributes. - *

    - * The standard OMS {@code Queue} schema must start with the {@code Namespace} prefix: - *

    - * {@literal ://} - * - * @param queueName the name of the new queue. - * @throws OMSSecurityException when have no authority to create this queue. - * @throws OMSTimeOutException when the given timeout elapses before the create operation completes. - * @throws OMSDestinationException when the given destination has been created in the server. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to delete the namespace due to some internal - * error. - */ - void createQueue(String queueName); - - /** - * Deletes an existing queue resource. - * - * @param queueName the queue needs to be deleted. - * @throws OMSSecurityException when have no authority to delete this namespace. - * @throws OMSTimeOutException when the given timeout elapses before the delete operation completes. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to delete the namespace due to some internal - * error. - */ - void deleteQueue(String queueName); - - /** - * Gets the queue list in the specific namespace. - * - * @param nsName the specific namespace. - * @return the set of queues exists in current namespace. - * @throws OMSSecurityException when have no authority to delete this namespace. - * @throws OMSTimeOutException when the given timeout elapses before the list operation completes. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to list the namespace due to some internal - * error. - */ - Set listQueues(String nsName); - - /** - * In order to enable consumers to get the message in the specified mode, the filter rule follows the sql standard - * to filter out messages. - * - * @param queueName queue name. - * @param filterString SQL expression to filter out messages. - * @throws OMSSecurityException when have no authority to add this filter. - * @throws OMSTimeOutException when the given timeout elapses before the add filter operation completes. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to add a new filter due to some internal - * error. - */ - void filter(String queueName, String filterString); - - /** - * Routing from sourceQueue to targetQueue. Both queues are could be received messages after creating route action. - * - * @param sourceQueue source queue, process messages received from producer and duplicate those to target queue. - * @param targetQueue receive messages from source queue. - * @throws OMSSecurityException when have no authority to add this routing. - * @throws OMSTimeOutException when the given timeout elapses before the routing operation completes. - * @throws OMSRuntimeException when the {@code ResourceManager} fails to add a new routing due to some internal - * error. - */ - void routing(String sourceQueue, String targetQueue); - -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/message/Header.java b/openmessaging-api/src/main/java/io/openmessaging/message/Header.java deleted file mode 100644 index 1017c687..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/message/Header.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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.message; - -import io.openmessaging.KeyValue; -import io.openmessaging.extension.ExtensionHeader; - -/** - * The {@code Header} interface is the root interface of all OMS messages, and the most commonly used by OMS message - * {@link Message}. - *

    - * The header contains fields used by the messaging system that describes the message's meta information, while the body - * contains the application data being transmitted. - *

    - * As for the message header, OMS defines three kinds types: headers {@link Header} {@link ExtensionHeader} and - * properties {@link KeyValue}, with respect to flexibility in vendor implementation and user usage. - *

      - *
    • - * System Headers, OMS defines some standard attributes that represent the characteristics of the message. - *
    • - * - *
    - * The body contains the application data being transmitted, which is generally ignored by the messaging system and - * simply transmitted to its destination. - *

    - * - * The header part is placed in the implementation classes of {@code Message}. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface Header { - /** - * The {@code DESTINATION} header field contains the destination to which the message is being sent. - *

    - * When a message is set to the {@code Queue}, then the message will be sent to the specified destination. - *

    - * When a message is received, its destination is equivalent to the {@code Queue} where the message resides in. - */ - Header setDestination(String destination); - - /** - * The {@code MESSAGE_ID} header field contains a value that uniquely identify each message sent by a {@code - * Producer}. this identifier is generated by producer. - */ - Header setMessageId(String messageId); - - /** - * The {@code BORN_TIMESTAMP} header field contains the time a message was handed off to a {@code Producer} to be - * sent. - *

    - * When a message is sent, BORN_TIMESTAMP will be set with current timestamp as the born timestamp of a message in - * client side, on return from the send method, the message's BORN_TIMESTAMP header field contains this value. - *

    - * When a message is received its, BORN_TIMESTAMP header field contains this same value. - *

    - * This filed is a {@code long} value, measured in milliseconds. - */ - Header setBornTimestamp(long bornTimestamp); - - /** - * The {@code BORN_HOST} header field contains the born host info of a message in client side. - *

    - * When a message is sent, BORN_HOST will be set with the local host info, on return from the send method, the - * message's BORN_HOST header field contains this value. - *

    - * When a message is received, its BORN_HOST header field contains this same value. - */ - Header setBornHost(String bornHost); - - /** - * The {@code PRIORITY} header field contains the priority level of a message, a message with a higher priority - * value should be delivered preferentially. - *

    - * OMS defines a ten level priority value with 1 as the lowest priority and 10 as the highest, and the default - * priority is 5. The priority beyond this region will be ignored. - *

    - * OMS does not require or provide any guarantee that the message should be delivered in priority order strictly, - * but the vendor should provide a best effort to deliver expedited messages ahead of normal messages. - *

    - * If PRIORITY field isn't set explicitly, use {@code 5} as the default priority. - */ - Header setPriority(short priority); - - /** - * The {@code DURABILITY} header field contains the persistent level of a message, the vendor should guarantee the - * reliability level for a message. - *

    - * OMS defines two modes of message delivery: - *

      - *
    • - * PERSISTENT, the persistent mode instructs the vendor should provide stable storage to ensure the message won't be - * lost. - *
    • - *
    • - * NON_PERSISTENT, this mode does not require the message be logged to stable storage, in most cases, the memory - * storage is enough for better performance and lower cost. - *
    • - *
    - */ - Header setDurability(short durability); - - /** - * The {@code DELIVERY_COUNT} header field contains a number, which represents the count of the message delivery. - */ - Header setDeliveryCount(int deliveryCount); - - /** - * The field {@code COMPRESSION} in headers represents the message body compress algorithm. vendors are free to - * choose the compression algorithm, but must ensure that the decompressed message is delivered to the user. - */ - Header setCompression(short compression); - - /** - * See {@link Header#setDestination(String)} - * - * @return destination - */ - String getDestination(); - - /** - * See {@link Header#setMessageId(String)} - * - * @return messageId - */ - String getMessageId(); - - /** - * See {@link Header#setBornTimestamp(long)} - * - * @return bornTimestamp - */ - long getBornTimestamp(); - - /** - * See {@link Header#setBornHost(String)} - * - * @return bornHost - */ - String getBornHost(); - - /** - * See {@link Header#setPriority(short)} - * - * @return priority - */ - short getPriority(); - - /** - * See {@link Header#setDurability(short)} - * - * @return durability - */ - short getDurability(); - - /** - * See {@link Header#setDeliveryCount(int)} - * - * @return deliveryCount - */ - int getDeliveryCount(); - - /** - * See {@link Header#setCompression(short)} - * - * @return compression - */ - short getCompression(); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/message/Message.java b/openmessaging-api/src/main/java/io/openmessaging/message/Message.java deleted file mode 100644 index a43d23ed..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/message/Message.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.message; - -import io.openmessaging.KeyValue; -import io.openmessaging.annotation.Optional; -import io.openmessaging.consumer.BatchMessageListener; -import io.openmessaging.consumer.Consumer; -import io.openmessaging.consumer.MessageListener; -import io.openmessaging.consumer.MessageReceipt; -import io.openmessaging.exception.OMSMessageFormatException; -import io.openmessaging.extension.ExtensionHeader; - -/** - * The {@code Message} interface is the root interface of all OMS messages, and the most commonly used OMS message is - * {@link Message}. - *

    - * Most message-oriented middleware (MOM) products treat messages as lightweight entities that consist of header and - * body and is used by separate applications to exchange a piece of information, like Apache RocketMQ. - *

    - * The header contains fields used by the messaging system that describes the message's meta information, while the body - * contains the application data being transmitted. - *

    - * As for the message header, OMS defines three kinds types: headers {@link Header} {@link ExtensionHeader} and - * properties {@link KeyValue}, with respect to flexibility in vendor implementation and user usage. - *

      - *
    • - * System Headers, OMS defines some standard attributes that represent the characteristics of the message. - *
    • - *
    • - * User properties, some OMS vendors may require enhanced extra attributes of the message or some users may want to - * clarify some customized attributes to draw the body. OMS provides the improved scalability for these scenarios. - *
    • - *
    - * The body contains the application data being transmitted, which is generally ignored by the messaging system and - * simply transmitted to its destination. - *

    - * In BytesMessage, the body is just a byte array, may be compressed and uncompressed in the transmitting process by the - * messaging system. The application is responsible for explaining the concrete content and format of the message body, - * OMS is never aware of that. - * - * The body part is placed in the implementation classes of {@code Message}. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface Message { - /** - * Returns all the system header fields of the {@code Message} object as a {@code KeyValue}. - * - * @return the system headers of a {@code Message} - */ - Header header(); - - /** - * This interface is optional, Therefore, users need to check whether the interface is implemented and the - * correctness of its implementation. - *

    - * - * @return The implementation of {@link ExtensionHeader} - */ - @Optional - ExtensionHeader extensionHeader(); - - /** - * Returns all the customized user header fields of the {@code Message} object as a {@code KeyValue}. - * - * @return the user properties of a {@code Message} - */ - KeyValue properties(); - - /** - * Get data from message body - * - * @return message body - * @throws OMSMessageFormatException if the message body cannot be assigned to the specified type - */ - byte[] getData(); - - /** - * Set data to message body - * - * @param data set message body in binary stream - */ - void setData(byte[] data); - - /** - * Get the {@code MessageReceipt} of this Message, which will be used to acknowledge this message. - * - * @see Consumer#ack(io.openmessaging.consumer.MessageReceipt) - * @see MessageListener.Context#ack() - * @see BatchMessageListener.Context#success(io.openmessaging.consumer.MessageReceipt...) - */ - MessageReceipt getMessageReceipt(); - -} \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/message/MessageFactory.java b/openmessaging-api/src/main/java/io/openmessaging/message/MessageFactory.java deleted file mode 100644 index 4902d4b6..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/message/MessageFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.message; - -import io.openmessaging.exception.OMSMessageFormatException; -import io.openmessaging.message.Message; - -/** - * A factory interface for creating {@code Message} objects. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface MessageFactory { - /** - * Creates a {@code Message} object. A {@code Message} object is used to send a message containing a stream of - * uninterpreted bytes. - *

    - * The returned {@code Message} object only can be sent to the specified queue. - * - * @param queueName the target queue to send - * @param body the body data for a message - * @return the created {@code Message} object - * @throws OMSMessageFormatException when body exceed the maximum length or others. - */ - Message createMessage(String queueName, byte[] body); -} \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/producer/Producer.java b/openmessaging-api/src/main/java/io/openmessaging/producer/Producer.java deleted file mode 100644 index 3dbc10d4..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/producer/Producer.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.producer; - -import io.openmessaging.Client; -import io.openmessaging.Future; -import io.openmessaging.FutureListener; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.ServiceLifecycle; -import io.openmessaging.exception.OMSDestinationException; -import io.openmessaging.exception.OMSMessageFormatException; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.exception.OMSTimeOutException; -import io.openmessaging.exception.OMSTransactionException; -import io.openmessaging.interceptor.ProducerInterceptor; -import io.openmessaging.message.Message; -import io.openmessaging.message.MessageFactory; -import java.util.List; - -/** - * A {@code Producer} is a simple object used to send messages on behalf of a {@code MessagingAccessPoint}. An instance - * of {@code Producer} is created by calling the {@link MessagingAccessPoint#createProducer()} method. - *

    - * It provides various {@code send} methods to send a message to a specified destination, which is a {@code Queue} in - * OMS. - *

    - * {@link Producer#send(Message)} means send a message to the destination synchronously, the calling thread will block - * until the send request complete. - *

    - * {@link Producer#sendAsync(Message)} means send a message to the destination asynchronously, the calling thread won't - * block and will return immediately. Since the send call is asynchronous it returns a {@link Future} for the send - * result. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface Producer extends MessageFactory, ServiceLifecycle, Client { - - /** - * Sends a message to the specified destination synchronously, the destination should be preset to {@link - * Message#header()}, other header fields as well. - * - * @param message a message will be sent. - * @return the successful {@code SendResult}. - * @throws OMSSecurityException when have no authority to send messages to a given destination. - * @throws OMSMessageFormatException when an invalid message is specified. - * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - */ - SendResult send(Message message); - - /** - * Sends a message to the specified destination asynchronously, the destination should be preset to {@link - * Message#header()}, other header fields as well. - *

    - * The returned {@code Promise} will have the result once the operation completes, and the registered {@code - * FutureListener} will be notified, either because the operation was successful or because of an error. - * - * @param message a message will be sent. - * @return the {@code Promise} of an asynchronous message send operation. - * @see Future - * @see FutureListener - */ - Future sendAsync(Message message); - - /** - *

    - * There is no {@code Promise} related or {@code RuntimeException} thrown. The calling thread doesn't care about the - * send result and also have no context to get the result. - * - * @param message a message will be sent. - */ - void sendOneway(Message message); - - /** - *

    - * Send batch messages to server. - * - * @param messages messages to be sent. - */ - void send(List messages); - - /** - * Send messages to the specified destination asynchronously, the destination should be preset to {@link - * Message#header()}, other header fields as well. - *

    - * The returned {@code Promise} will have the result once the operation completes, and the registered {@code - * FutureListener} will be notified, either because the operation was successful or because of an error. - * - * @param messages a batch messages will be sent. - * @return the {@code Promise} of an asynchronous messages send operation. - * @see Future - * @see FutureListener - */ - Future sendAsync(List messages); - - /** - *

    - * There is no {@code Promise} related or {@code RuntimeException} thrown. The calling thread doesn't care about the - * send result and also have no context to get the result. - * - * @param messages a batch message will be sent. - */ - void sendOneway(List messages); - - /** - * Adds a {@code ProducerInterceptor} to intercept send operations of producer. - * - * @param interceptor a producer interceptor. - */ - void addInterceptor(ProducerInterceptor interceptor); - - /** - * Remove a {@code ProducerInterceptor}. - * - * @param interceptor a producer interceptor will be removed. - */ - void removeInterceptor(ProducerInterceptor interceptor); - - /** - * Sends a transactional message to the specified destination synchronously, the destination should be preset to - * {@link Message#header()}, other header fields as well. - *

    - * 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 SendResult}. - * @throws OMSSecurityException when have no authority to send messages to a given destination. - * @throws OMSMessageFormatException when an invalid message is specified. - * @throws OMSTimeOutException when the given timeout elapses before the send operation completes. - * @throws OMSDestinationException when have no given destination in the server. - * @throws OMSRuntimeException when the {@code Producer} fails to send the message due to some internal error. - * @throws OMSTransactionException when used normal producer which haven't register {@link - * TransactionStateCheckListener}. - */ - TransactionalResult prepare(Message message); - -} \ No newline at end of file diff --git a/openmessaging-api/src/main/java/io/openmessaging/producer/SendResult.java b/openmessaging-api/src/main/java/io/openmessaging/producer/SendResult.java deleted file mode 100644 index 84b3241b..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/producer/SendResult.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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.producer; - -/** - * The result of sending a OMS message to server with the message id and some attributes. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface SendResult { - /** - * The unique message id related to the {@code SendResult} instance. - * - * @return the message id. - */ - String messageId(); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/producer/TransactionStateCheckListener.java b/openmessaging-api/src/main/java/io/openmessaging/producer/TransactionStateCheckListener.java deleted file mode 100644 index efa0d5f1..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/producer/TransactionStateCheckListener.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.producer; - -import io.openmessaging.message.Message; - -/** - * Each executor will be associated with a transactional message, can be used to execute local transaction branch and - * submit the transaction status(commit or rollback). - *

    - * - * The associated message will be exposed to consumer when the local transaction has been committed, or be discarded if - * local transaction has been rolled back. - * - *

    - * If the executor doesn't submit the transaction status for a long time, the server may lookup it forwardly through - * {@link TransactionStateCheckListener#check(Message, TransactionalContext)} - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface TransactionStateCheckListener { - - /** - * Checks the status of the local transaction branch. - * - * @param message the associated message. - * @param context the check context. - */ - void check(Message message, TransactionalContext context); - - interface TransactionalContext { - /** - * Commits a transaction. - */ - void commit(); - - /** - * Rolls back a transaction. - */ - void rollback(); - - /** - * Unknown transaction status, may be this transaction still on going. - */ - void unknown(); - } -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/producer/TransactionalResult.java b/openmessaging-api/src/main/java/io/openmessaging/producer/TransactionalResult.java deleted file mode 100644 index ed1644b8..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/producer/TransactionalResult.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.producer; - -/** - * The result of sending a OMS prepare message to server with the message id, this result can be used to commits or or - * rolls back a prepare message. - * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface TransactionalResult extends SendResult { - /** - * The unique transactionId id related to the {@code TransactionResult} instance. - * - * @return the transactional id - */ - String transactionId(); - - /** - * Commits a transaction. - */ - void commit(); - - /** - * Rolls back a transaction. - */ - void rollback(); -} diff --git a/openmessaging-api/src/test/java/io/openmessaging/internal/InternalErrorCodeTest.java b/openmessaging-api/src/test/java/io/openmessaging/api/internal/InternalErrorCodeTest.java similarity index 90% rename from openmessaging-api/src/test/java/io/openmessaging/internal/InternalErrorCodeTest.java rename to openmessaging-api/src/test/java/io/openmessaging/api/internal/InternalErrorCodeTest.java index f13833bb..17d14bd2 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/InternalErrorCodeTest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/api/internal/InternalErrorCodeTest.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package io.openmessaging.internal; +package io.openmessaging.api.internal; -import io.openmessaging.OMSResponseStatus; -import io.openmessaging.exception.OMSRuntimeException; +import io.openmessaging.api.OMSResponseStatus; +import io.openmessaging.api.exception.OMSRuntimeException; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java b/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java new file mode 100644 index 00000000..9f010026 --- /dev/null +++ b/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java @@ -0,0 +1,94 @@ +/* + * 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.internal; + +import io.openmessaging.api.Consumer; +import io.openmessaging.api.MessagingAccessPoint; +import io.openmessaging.api.OMS; +import io.openmessaging.api.Producer; +import io.openmessaging.api.PullConsumer; +import io.openmessaging.api.batch.BatchConsumer; +import io.openmessaging.api.order.OrderConsumer; +import io.openmessaging.api.order.OrderProducer; +import io.openmessaging.api.transaction.LocalTransactionChecker; +import io.openmessaging.api.transaction.TransactionProducer; +import java.util.Properties; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MessagingAccessPointAdapterTest { + @Test + public void getMessagingAccessPoint() { + + final MessagingAccessPoint messagingAccessPoint = + OMS.builder() + .region("Shenzhen") + .endpoint("127.0.0.1:9876") + .driverImpl("io.openmessaging.api.internal.TestVendor") + .withCredentials(new Properties()) + .build(); + + assertThat(messagingAccessPoint).isExactlyInstanceOf(TestVendor.class); + } +} + +class TestVendor implements MessagingAccessPoint { + private Properties properties; + + public TestVendor(Properties properties) { + this.properties = properties; + } + + @Override public String version() { + return "1.2.1"; + } + + @Override public Properties attributes() { + return null; + } + + @Override public Producer createProducer(Properties properties) { + return null; + } + + @Override public OrderProducer createOrderProducer(Properties properties) { + return null; + } + + @Override public TransactionProducer createTransactionProducer(Properties properties, + LocalTransactionChecker checker) { + return null; + } + + @Override public Consumer createConsumer(Properties properties) { + return null; + } + + @Override public PullConsumer createPullConsumer(Properties properties) { + return null; + } + + @Override public BatchConsumer createBatchConsumer(Properties properties) { + return null; + } + + @Override public OrderConsumer createOrderedConsumer(Properties properties) { + return null; + } +} \ No newline at end of file diff --git a/openmessaging-api/src/test/java/io/openmessaging/internal/AccessPointURITest.java b/openmessaging-api/src/test/java/io/openmessaging/internal/AccessPointURITest.java deleted file mode 100644 index b11ff408..00000000 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/AccessPointURITest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.internal; - -import io.openmessaging.exception.OMSRuntimeException; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Fail.failBecauseExceptionWasNotThrown; - -public class AccessPointURITest { - private String fullSchemaURI = "oms:rocketmq://alice@rocketmq.apache.org/us-east"; - - @Test - public void testParse_DriverIsIllegal() { - String missDriverType = "oms://alice@rocketmq.apache.org/us-east"; - try { - new AccessPointURI(missDriverType); - failBecauseExceptionWasNotThrown(OMSRuntimeException.class); - } catch (Exception e) { - assertThat(e).hasMessageContaining(String.format("The OMS driver URL [%s] is illegal.", missDriverType)); - } - - - String missRegion = "oms:rocketmq://alice@rocketmq.apache.org/"; - try { - new AccessPointURI(missRegion); - failBecauseExceptionWasNotThrown(OMSRuntimeException.class); - } catch (Exception e) { - assertThat(e).hasMessageContaining(String.format("The OMS driver URL [%s] is illegal.", missRegion)); - } - } - - @Test - public void testGetAccessPointString() { - AccessPointURI accessPointURI = new AccessPointURI(fullSchemaURI); - assertThat(accessPointURI.getAccessPointString()).isEqualTo(fullSchemaURI); - } - - @Test - public void testGetDriverType() { - AccessPointURI accessPointURI = new AccessPointURI(fullSchemaURI); - assertThat(accessPointURI.getDriverType()).isEqualTo("rocketmq"); - } - - @Test - public void testGetAccountId() { - AccessPointURI accessPointURI = new AccessPointURI(fullSchemaURI); - assertThat(accessPointURI.getAccountId()).isEqualTo("alice"); - } - - @Test - public void testGetHosts() { - AccessPointURI accessPointURI = new AccessPointURI(fullSchemaURI); - assertThat(accessPointURI.getHosts()).isEqualTo("rocketmq.apache.org"); - - String multipleHostsURI = "oms:rocketmq://alice@rocketmq.apache.org,pulsar.apache.org:9091/us-east:default_space"; - accessPointURI = new AccessPointURI(multipleHostsURI); - assertThat(accessPointURI.getHosts()).isEqualTo("rocketmq.apache.org,pulsar.apache.org:9091"); - } - - @Test - public void testGetRegion() { - AccessPointURI accessPointURI = new AccessPointURI(fullSchemaURI); - - assertThat(accessPointURI.getRegion()).isEqualTo("us-east"); - } -} \ No newline at end of file diff --git a/openmessaging-api/src/test/java/io/openmessaging/internal/DefaultKeyValueTest.java b/openmessaging-api/src/test/java/io/openmessaging/internal/DefaultKeyValueTest.java deleted file mode 100644 index 71d70484..00000000 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/DefaultKeyValueTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.internal; - -import io.openmessaging.KeyValue; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultKeyValueTest { - private KeyValue keyValue = new DefaultKeyValue(); - - @Test - public void testPutAndGet() throws Exception { - keyValue.put("IntKey", 123); - assertThat(keyValue.getInt("IntKey")).isEqualTo(123); - - keyValue.put("StringKey", "HELLO"); - assertThat(keyValue.getString("StringKey")).isEqualTo("HELLO"); - - keyValue.put("LongKey", 123L); - assertThat(keyValue.getLong("LongKey")).isEqualTo(123L); - - keyValue.put("DoubleKey", 1.23); - assertThat(keyValue.getDouble("DoubleKey")).isEqualTo(1.23); - } - - @Test - public void testKeySet() throws Exception { - keyValue.put("IndexKey", 123); - assertThat(keyValue.keySet()).contains("IndexKey"); - } - - @Test - public void testContainsKey() throws Exception { - keyValue.put("ContainsKey", 123); - assertThat(keyValue.containsKey("ContainsKey")).isTrue(); - } - -} \ No newline at end of file diff --git a/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java b/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java deleted file mode 100644 index b348996e..00000000 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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.internal; - -import io.openmessaging.KeyValue; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.OMSBuiltinKeys; -import io.openmessaging.consumer.Consumer; -import io.openmessaging.consumer.PullConsumer; -import io.openmessaging.consumer.PushConsumer; -import io.openmessaging.manager.ResourceManager; -import io.openmessaging.message.MessageFactory; -import io.openmessaging.producer.Producer; -import io.openmessaging.producer.TransactionStateCheckListener; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class MessagingAccessPointAdapterTest { - @Test - public void getMessagingAccessPoint() { - String testURI = "oms:test-vendor://alice@rocketmq.apache.org/us-east:default_space"; - - KeyValue keyValue = OMS.newKeyValue(); - keyValue.put(OMSBuiltinKeys.DRIVER_IMPL, "io.openmessaging.internal.TestVendor"); - MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint(testURI, keyValue); - assertThat(messagingAccessPoint).isExactlyInstanceOf(TestVendor.class); - } -} - -class TestVendor implements MessagingAccessPoint { - - public TestVendor(KeyValue keyValue) { - } - - @Override - public Producer createProducer(TransactionStateCheckListener transactionStateCheckListener) { - return null; - } - - @Override - public PushConsumer createPushConsumer() { - return null; - } - - @Override - public PullConsumer createPullConsumer() { - return null; - } - - @Override - public PushConsumer createPushConsumer(KeyValue attributes) { - return null; - } - - @Override - public PullConsumer createPullConsumer(KeyValue attributes) { - return null; - } - - @Override - public MessageFactory messageFactory() { - return null; - } - - @Override - public String version() { - return OMS.specVersion; - } - - @Override - public KeyValue attributes() { - return null; - } - - @Override - public Producer createProducer() { - return null; - } - - @Override - public ResourceManager resourceManager() { - return null; - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0ef1d346..2e1269fc 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 1.0.0-beta-SNAPSHOT + 2.0.2-pubsub-SNAPSHOT pom openmessaging @@ -51,8 +51,8 @@ UTF-8 - 1.8 - 1.8 + 1.7 + 1.7 @@ -122,7 +122,8 @@ UTF-8 en_US - io.openmessaging.internal + io.openmessaging.api.internal + -Xdoclint:none