From 61aa60a8d72bc546442866ea84abfd0ab4e0691f Mon Sep 17 00:00:00 2001 From: duhenglucky Date: Tue, 3 Sep 2019 18:35:16 +0800 Subject: [PATCH 01/23] Change the queue model to pubsub model --- openmessaging-admin/pom.xml | 2 +- openmessaging-api-samples/pom.xml | 6 +- .../samples/consumer/PullConsumerApp.java | 25 +- .../samples/consumer/PushConsumerApp.java | 38 ++- .../samples/producer/ProducerApp.java | 63 ++--- .../producer/TransactionProducerApp.java | 39 ++- .../samples/routing/RoutingApp.java | 83 ------ openmessaging-api/pom.xml | 2 +- .../{Client.java => Action.java} | 27 +- .../main/java/io/openmessaging/Constants.java | 21 ++ .../java/io/openmessaging/ConsumeContext.java | 21 ++ .../main/java/io/openmessaging/Consumer.java | 26 ++ .../java/io/openmessaging/Credentials.java | 22 ++ .../java/io/openmessaging/ExpressionType.java | 24 ++ .../main/java/io/openmessaging/Future.java | 4 +- .../java/io/openmessaging/FutureListener.java | 6 +- .../main/java/io/openmessaging/KeyValue.java | 230 ---------------- .../main/java/io/openmessaging/LifeCycle.java | 26 ++ .../main/java/io/openmessaging/Message.java | 250 ++++++++++++++++++ .../io/openmessaging/MessageAccessor.java | 40 +++ .../io/openmessaging/MessageListener.java | 23 ++ .../io/openmessaging/MessageSelector.java | 49 ++++ .../openmessaging/MessagingAccessPoint.java | 91 +++---- .../src/main/java/io/openmessaging/OMS.java | 19 +- .../java/io/openmessaging/OMSBuiltinKeys.java | 4 +- .../io/openmessaging/OnExceptionContext.java | 52 ++++ .../main/java/io/openmessaging/Producer.java | 32 +++ .../main/java/io/openmessaging/Promise.java | 65 ----- .../io/openmessaging/PropertyValueConst.java | 27 ++ .../java/io/openmessaging/PullConsumer.java | 143 ++++++++++ .../java/io/openmessaging/SendCallback.java | 24 ++ .../java/io/openmessaging/SendResult.java | 47 ++++ .../io/openmessaging/ServiceLifeState.java | 52 ---- .../io/openmessaging/ServiceLifecycle.java | 56 ---- .../java/io/openmessaging/TopicPartition.java | 78 ++++++ .../io/openmessaging/annotation/Optional.java | 43 --- .../io/openmessaging/batch/BatchConsumer.java | 28 ++ .../batch/BatchMessageListener.java | 29 ++ .../io/openmessaging/bean/Subscription.java | 93 +++++++ .../openmessaging/bean/SubscriptionExt.java | 47 ++++ .../consumer/BatchMessageListener.java | 59 ----- .../io/openmessaging/consumer/Consumer.java | 72 ----- .../consumer/MessageListener.java | 51 ---- .../consumer/MessageReceipt.java | 27 -- .../openmessaging/consumer/PullConsumer.java | 147 ---------- .../openmessaging/consumer/PushConsumer.java | 120 --------- .../exception/OMSDestinationException.java | 4 +- .../exception/OMSMessageFormatException.java | 4 +- .../exception/OMSRuntimeException.java | 23 +- .../exception/OMSSecurityException.java | 4 +- .../exception/OMSTimeOutException.java | 4 +- .../exception/OMSTransactionException.java | 4 +- .../exception/OMSUnsupportException.java | 7 +- .../io/openmessaging/extension/Extension.java | 51 ---- .../extension/ExtensionHeader.java | 201 -------------- .../extension/QueueMetaData.java | 66 ----- .../interceptor/ConsumerInterceptor.java | 45 ---- .../io/openmessaging/interceptor/Context.java | 35 --- .../interceptor/ProducerInterceptor.java | 49 ---- .../internal/DefaultKeyValue.java | 158 ----------- .../internal/MessagingAccessPointAdapter.java | 14 +- .../manager/ResourceManager.java | 158 ----------- .../java/io/openmessaging/message/Header.java | 183 ------------- .../io/openmessaging/message/Message.java | 112 -------- .../openmessaging/message/MessageFactory.java | 42 --- .../order/ConsumeOrderContext.java | 21 ++ .../order/MessageOrderListener.java | 25 ++ .../order/MessageQueueSelector.java | 25 ++ .../io/openmessaging/order/OrderAction.java | 26 ++ .../io/openmessaging/order/OrderConsumer.java | 29 ++ .../io/openmessaging/order/OrderProducer.java | 28 ++ .../io/openmessaging/producer/Producer.java | 159 ----------- .../io/openmessaging/producer/SendResult.java | 33 --- .../TransactionStateCheckListener.java | 63 ----- .../producer/TransactionalResult.java | 44 --- .../transaction/LocalTransactionChecker.java | 26 ++ .../transaction/LocalTransactionExecutor.java | 25 ++ .../transaction/TransactionProducer.java | 30 +++ .../transaction/TransactionStatus.java | 28 ++ .../internal/DefaultKeyValueTest.java | 55 ---- .../MessagingAccessPointAdapterTest.java | 59 ++--- pom.xml | 2 +- 82 files changed, 1558 insertions(+), 2717 deletions(-) delete mode 100644 openmessaging-api-samples/src/main/java/io/openmessaging/samples/routing/RoutingApp.java rename openmessaging-api/src/main/java/io/openmessaging/{Client.java => Action.java} (55%) create mode 100644 openmessaging-api/src/main/java/io/openmessaging/Constants.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/ConsumeContext.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/Consumer.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/Credentials.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/ExpressionType.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/KeyValue.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/LifeCycle.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/Message.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/MessageAccessor.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/MessageListener.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/MessageSelector.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/OnExceptionContext.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/Producer.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/Promise.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/PropertyValueConst.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/PullConsumer.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/SendCallback.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/SendResult.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/ServiceLifeState.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/ServiceLifecycle.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/TopicPartition.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/annotation/Optional.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/batch/BatchConsumer.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/batch/BatchMessageListener.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/bean/Subscription.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/bean/SubscriptionExt.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/consumer/BatchMessageListener.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/consumer/Consumer.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/consumer/MessageListener.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/consumer/MessageReceipt.java delete mode 100755 openmessaging-api/src/main/java/io/openmessaging/consumer/PullConsumer.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/consumer/PushConsumer.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/extension/Extension.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/extension/ExtensionHeader.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/extension/QueueMetaData.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/interceptor/ConsumerInterceptor.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/interceptor/Context.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/interceptor/ProducerInterceptor.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/internal/DefaultKeyValue.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/manager/ResourceManager.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/message/Header.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/message/Message.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/message/MessageFactory.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/order/ConsumeOrderContext.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/order/MessageOrderListener.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/order/MessageQueueSelector.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/order/OrderAction.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/order/OrderConsumer.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/order/OrderProducer.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/producer/Producer.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/producer/SendResult.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/producer/TransactionStateCheckListener.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/producer/TransactionalResult.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionChecker.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionExecutor.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionProducer.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionStatus.java delete mode 100644 openmessaging-api/src/test/java/io/openmessaging/internal/DefaultKeyValueTest.java diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index debe8f13..bdd1e69b 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.0.0-beta-SNAPSHOT + 1.1.0-SNAPSHOT 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index d35c519d..c5ee92c0 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 + 1.1.0-SNAPSHOT 4.0.0 jar openmessaging-api-samples - 1.0.0-beta-SNAPSHOT + 1.1.0-SNAPSHOT openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 1.0.0-beta-SNAPSHOT + 1.1.0-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..01ce66d2 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,42 @@ package io.openmessaging.samples.consumer; +import io.openmessaging.Message; 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.PullConsumer; +import io.openmessaging.TopicPartition; +import java.time.Duration; +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"); - + 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(Duration.ofMillis(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..023957f2 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,14 +17,14 @@ package io.openmessaging.samples.consumer; +import io.openmessaging.Action; +import io.openmessaging.ConsumeContext; +import io.openmessaging.Consumer; +import io.openmessaging.Message; +import io.openmessaging.MessageListener; 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 java.util.Properties; public class PushConsumerApp { public static void main(String[] args) { @@ -32,36 +32,30 @@ public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint("oms:rocketmq://localhost:10911/us-east"); - //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..a16d9cd5 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,52 @@ package io.openmessaging.samples.producer; -import io.openmessaging.Future; +import io.openmessaging.Message; 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.OnExceptionContext; +import io.openmessaging.Producer; +import io.openmessaging.SendCallback; +import io.openmessaging.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"); - 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..d8cb1f4d 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,25 @@ package io.openmessaging.samples.producer; -import io.openmessaging.message.Message; +import io.openmessaging.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.SendResult; +import io.openmessaging.transaction.LocalTransactionChecker; +import io.openmessaging.transaction.LocalTransactionExecutor; +import io.openmessaging.transaction.TransactionProducer; +import io.openmessaging.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) { - + final TransactionProducer producer = messagingAccessPoint.createTransactionProducer(new Properties(), new LocalTransactionChecker() { + @Override + public TransactionStatus check(Message msg) { + return TransactionStatus.CommitTransaction; } }); producer.start(); @@ -41,23 +44,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 LocalTransactionExecutor() { + @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/pom.xml b/openmessaging-api/pom.xml index 9e493ee9..d75d12c6 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.0.0-beta-SNAPSHOT + 1.1.0-SNAPSHOT 4.0.0 diff --git a/openmessaging-api/src/main/java/io/openmessaging/Client.java b/openmessaging-api/src/main/java/io/openmessaging/Action.java similarity index 55% rename from openmessaging-api/src/main/java/io/openmessaging/Client.java rename to openmessaging-api/src/main/java/io/openmessaging/Action.java index ed20ebad..4982b002 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Client.java +++ b/openmessaging-api/src/main/java/io/openmessaging/Action.java @@ -14,28 +14,13 @@ * 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; -/** - *

- * 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. - *

- * - * @version OMS 1.0.0 - * @since OMS 1.0.0 - */ -public interface Client { - /** - * Get the extension method, and this interface is optional, Therefore, users need to check whether this interface - * has been implemented by vendors. - *

- * - * @return the implementation of {@link Extension} - */ - @io.openmessaging.annotation.Optional - Optional getExtension(); +public enum Action { + + CommitMessage, + + ReconsumeLater, } diff --git a/openmessaging-api/src/main/java/io/openmessaging/Constants.java b/openmessaging-api/src/main/java/io/openmessaging/Constants.java new file mode 100644 index 00000000..cdbdee21 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/Constants.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; + +public class Constants { + public static final String TRANSACTION_ID = "__transactionId__"; +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/ConsumeContext.java b/openmessaging-api/src/main/java/io/openmessaging/ConsumeContext.java new file mode 100644 index 00000000..c49b06bb --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/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; + +public class ConsumeContext { + +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/Consumer.java b/openmessaging-api/src/main/java/io/openmessaging/Consumer.java new file mode 100644 index 00000000..a06c265a --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/Consumer.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; + +public interface Consumer extends LifeCycle, Credentials { + + void subscribe(final String topic, final String subExpression, final MessageListener listener); + + void subscribe(final String topic, final MessageSelector selector, final MessageListener listener); + + void unsubscribe(final String topic); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/Credentials.java b/openmessaging-api/src/main/java/io/openmessaging/Credentials.java new file mode 100644 index 00000000..cb94a742 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/Credentials.java @@ -0,0 +1,22 @@ +/* + * 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.Properties; + +public interface Credentials { + void updateCredential(Properties credentialProperties); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/ExpressionType.java b/openmessaging-api/src/main/java/io/openmessaging/ExpressionType.java new file mode 100644 index 00000000..4cd89a36 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/ExpressionType.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.openmessaging; + +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/Future.java index e0973549..ff57d01d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Future.java +++ b/openmessaging-api/src/main/java/io/openmessaging/Future.java @@ -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/FutureListener.java index 866d7449..767df010 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/FutureListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/FutureListener.java @@ -22,13 +22,13 @@ * {@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/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/LifeCycle.java b/openmessaging-api/src/main/java/io/openmessaging/LifeCycle.java new file mode 100644 index 00000000..b4d4ec32 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/LifeCycle.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; +public interface LifeCycle { + boolean isStarted(); + + boolean isClosed(); + + void start(); + + void shutdown(); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/Message.java b/openmessaging-api/src/main/java/io/openmessaging/Message.java new file mode 100644 index 00000000..84a93360 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/Message.java @@ -0,0 +1,250 @@ +/* + * 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.io.Serializable; +import java.util.Properties; + +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)); + } + + @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"; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/MessageAccessor.java b/openmessaging-api/src/main/java/io/openmessaging/MessageAccessor.java new file mode 100644 index 00000000..3b67e4d3 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/MessageAccessor.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; + +import java.util.Properties; + +public class MessageAccessor { + public static Properties getSystemProperties(final Message msg) { + return msg.systemProperties; + } + + + public static void setSystemProperties(final Message msg, Properties systemProperties) { + msg.systemProperties = systemProperties; + } + + + public static void putSystemProperties(final Message msg, final String key, final String value) { + msg.putSystemProperties(key, value); + } + + + public static String getSystemProperties(final Message msg, final String key) { + return msg.getSystemProperties(key); + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/MessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/MessageListener.java new file mode 100644 index 00000000..1788973a --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/MessageListener.java @@ -0,0 +1,23 @@ +/* + * 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; + + +public interface MessageListener { + + Action consume(final Message message, final ConsumeContext context); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/MessageSelector.java b/openmessaging-api/src/main/java/io/openmessaging/MessageSelector.java new file mode 100644 index 00000000..ca6cc77e --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/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; + +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/MessagingAccessPoint.java index 80bee1dd..a7ca1022 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/MessagingAccessPoint.java +++ b/openmessaging-api/src/main/java/io/openmessaging/MessagingAccessPoint.java @@ -17,17 +17,14 @@ package io.openmessaging; -import io.openmessaging.consumer.Consumer; -import io.openmessaging.consumer.MessageListener; -import io.openmessaging.consumer.PullConsumer; -import io.openmessaging.consumer.PushConsumer; +import io.openmessaging.batch.BatchConsumer; 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.order.OrderConsumer; +import io.openmessaging.order.OrderProducer; +import io.openmessaging.transaction.LocalTransactionChecker; +import io.openmessaging.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 +36,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 { @@ -69,7 +65,7 @@ public interface MessagingAccessPoint { * * @return the attributes */ - KeyValue attributes(); + Properties attributes(); /** * Creates a new {@code Producer} for the specified {@code MessagingAccessPoint}. @@ -79,75 +75,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/OMS.java b/openmessaging-api/src/main/java/io/openmessaging/OMS.java index 4f3d9342..ba88c8b0 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMS.java +++ b/openmessaging-api/src/main/java/io/openmessaging/OMS.java @@ -18,9 +18,7 @@ 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; @@ -38,9 +36,8 @@ * 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 + * @version OMS 1.1.0 + * @since OMS 1.1.0 */ public final class OMS { /** @@ -52,7 +49,7 @@ public final class OMS { * some syntax error or internal error. */ public static MessagingAccessPoint getMessagingAccessPoint(String url) { - return getMessagingAccessPoint(url, OMS.newKeyValue()); + return getMessagingAccessPoint(url, new Properties()); } /** @@ -67,18 +64,10 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url) { * @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) { + public static MessagingAccessPoint getMessagingAccessPoint(String url, Properties 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 diff --git a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java b/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java index 7d47d9a6..37084672 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java +++ b/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java @@ -20,8 +20,8 @@ /** * 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 { /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/OnExceptionContext.java b/openmessaging-api/src/main/java/io/openmessaging/OnExceptionContext.java new file mode 100644 index 00000000..145ed300 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/OnExceptionContext.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.openmessaging; + +import io.openmessaging.exception.OMSRuntimeException; + +public class OnExceptionContext { + + private String messageId; + + private String topic; + + 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/Producer.java b/openmessaging-api/src/main/java/io/openmessaging/Producer.java new file mode 100644 index 00000000..27c76bb6 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/Producer.java @@ -0,0 +1,32 @@ +/* + * 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.concurrent.ExecutorService; + +public interface Producer extends LifeCycle, Credentials { + + SendResult send(final Message message); + + void sendOneway(final Message message); + + void sendAsync(final Message message, final SendCallback sendCallback); + + void setCallbackExecutor(final ExecutorService callbackExecutor); + + SendResult send(final Message message, final String shardingKey); +} 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/PropertyValueConst.java b/openmessaging-api/src/main/java/io/openmessaging/PropertyValueConst.java new file mode 100644 index 00000000..3a1e7b07 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/PropertyValueConst.java @@ -0,0 +1,27 @@ +/* + * 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; + + +public class PropertyValueConst { + + + public static final String BROADCASTING = "BROADCASTING"; + + + public static final String CLUSTERING = "CLUSTERING"; +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/PullConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/PullConsumer.java new file mode 100644 index 00000000..21fa8304 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/PullConsumer.java @@ -0,0 +1,143 @@ +/* + * 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.time.Duration; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +public interface PullConsumer extends LifeCycle, Credentials { + + 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 + * @return + */ + List poll(Duration timeout); + + /** + * Overrides the fetch offsets that the consumer will use on the next {@link #poll(Duration)} }. 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(Duration)} }. + * + * @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(Duration)} }. + * + * @param topicPartition + */ + void seekToEnd(TopicPartition topicPartition); + + /** + * Suspend fetching from the requested message queues. Future calls to {@link #poll(Duration)} 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(Duration)} 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/SendCallback.java b/openmessaging-api/src/main/java/io/openmessaging/SendCallback.java new file mode 100644 index 00000000..0c79e626 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/SendCallback.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.openmessaging; + +public interface SendCallback { + + void onSuccess(final SendResult sendResult); + + void onException(final OnExceptionContext context); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/SendResult.java b/openmessaging-api/src/main/java/io/openmessaging/SendResult.java new file mode 100644 index 00000000..aff1b888 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/SendResult.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; + +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/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/ServiceLifecycle.java b/openmessaging-api/src/main/java/io/openmessaging/ServiceLifecycle.java deleted file mode 100644 index 3066cd56..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/ServiceLifecycle.java +++ /dev/null @@ -1,56 +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.consumer.Consumer; -import io.openmessaging.extension.Extension; -import io.openmessaging.producer.Producer; - -/** - * The {@code ServiceLifecycle} 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 - */ -public interface ServiceLifecycle extends Extension { - /** - * 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. - */ - void start(); - - /** - * 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(); - -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/TopicPartition.java b/openmessaging-api/src/main/java/io/openmessaging/TopicPartition.java new file mode 100644 index 00000000..88668061 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/TopicPartition.java @@ -0,0 +1,78 @@ +/* + * 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; + +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; + } +} 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/batch/BatchConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/batch/BatchConsumer.java new file mode 100644 index 00000000..1cd6072f --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/batch/BatchConsumer.java @@ -0,0 +1,28 @@ +/* + * 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.batch; + +import io.openmessaging.Credentials; +import io.openmessaging.LifeCycle; + +public interface BatchConsumer extends LifeCycle, Credentials { + + void subscribe(final String topic, final String subExpression, final BatchMessageListener listener); + + void unsubscribe(final String topic); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/batch/BatchMessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/batch/BatchMessageListener.java new file mode 100644 index 00000000..ca3adb98 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/batch/BatchMessageListener.java @@ -0,0 +1,29 @@ +/* + * 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.batch; + +import io.openmessaging.Action; +import io.openmessaging.ConsumeContext; +import io.openmessaging.Message; +import java.util.List; + + +public interface BatchMessageListener { + + Action consume(final List messages, final ConsumeContext context); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/bean/Subscription.java b/openmessaging-api/src/main/java/io/openmessaging/bean/Subscription.java new file mode 100644 index 00000000..523fda3e --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/bean/Subscription.java @@ -0,0 +1,93 @@ +/* + * 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.bean; + +import io.openmessaging.ExpressionType; + +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/bean/SubscriptionExt.java b/openmessaging-api/src/main/java/io/openmessaging/bean/SubscriptionExt.java new file mode 100644 index 00000000..1d173293 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/bean/SubscriptionExt.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.bean; + + +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/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/exception/OMSDestinationException.java b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSDestinationException.java index 495876de..5f6919dd 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSDestinationException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSDestinationException.java @@ -21,8 +21,8 @@ * 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/exception/OMSMessageFormatException.java index 69c47835..3175449e 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSMessageFormatException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSMessageFormatException.java @@ -21,8 +21,8 @@ * 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/exception/OMSRuntimeException.java index 9578786d..d93f68a5 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSRuntimeException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSRuntimeException.java @@ -17,6 +17,8 @@ package io.openmessaging.exception; +import io.openmessaging.OMSResponseStatus; + /** * This is the root class of all unchecked exceptions in the OMS API. *

@@ -26,20 +28,30 @@ *

  • 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; + public OMSRuntimeException(String message) { + super(message); + 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 +73,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/exception/OMSSecurityException.java index 2480399e..91550cd8 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSSecurityException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSSecurityException.java @@ -20,8 +20,8 @@ /** * 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/exception/OMSTimeOutException.java index 05555897..72b0b690 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTimeOutException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTimeOutException.java @@ -22,8 +22,8 @@ *

    * 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/exception/OMSTransactionException.java index 07523790..a05713f3 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTransactionException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSTransactionException.java @@ -20,8 +20,8 @@ /** * 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/exception/OMSUnsupportException.java index 5720d452..f6a698f1 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/exception/OMSUnsupportException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/exception/OMSUnsupportException.java @@ -16,14 +16,13 @@ */ package io.openmessaging.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/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/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/internal/MessagingAccessPointAdapter.java b/openmessaging-api/src/main/java/io/openmessaging/internal/MessagingAccessPointAdapter.java index ad68dcbf..0b5f8bd8 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/MessagingAccessPointAdapter.java +++ b/openmessaging-api/src/main/java/io/openmessaging/internal/MessagingAccessPointAdapter.java @@ -17,13 +17,13 @@ package io.openmessaging.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 java.lang.reflect.Constructor; +import java.util.Properties; import static io.openmessaging.OMSResponseStatus.generateException; @@ -31,8 +31,8 @@ * 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 { /** @@ -43,7 +43,7 @@ public class MessagingAccessPointAdapter { * @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) { + public static MessagingAccessPoint getMessagingAccessPoint(String url, Properties attributes) { AccessPointURI accessPointURI = new AccessPointURI(url); String driverImpl = parseDriverImpl(accessPointURI.getDriverType(), attributes); @@ -54,7 +54,7 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url, KeyValue 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; @@ -63,9 +63,9 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url, KeyValue } } - 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"; } 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/order/ConsumeOrderContext.java b/openmessaging-api/src/main/java/io/openmessaging/order/ConsumeOrderContext.java new file mode 100644 index 00000000..2143b1df --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/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.order; + +public class ConsumeOrderContext { + +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/MessageOrderListener.java b/openmessaging-api/src/main/java/io/openmessaging/order/MessageOrderListener.java new file mode 100644 index 00000000..5c9f7c4f --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/order/MessageOrderListener.java @@ -0,0 +1,25 @@ +/* + * 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.order; + +import io.openmessaging.Message; + +public interface MessageOrderListener { + + OrderAction consume(final Message message, final ConsumeOrderContext context); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/MessageQueueSelector.java b/openmessaging-api/src/main/java/io/openmessaging/order/MessageQueueSelector.java new file mode 100644 index 00000000..b8684988 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/order/MessageQueueSelector.java @@ -0,0 +1,25 @@ +/* + * 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.order; + +import io.openmessaging.Message; + +public interface MessageQueueSelector { + + int select(final int queueTotal, final Message msg, final Object arg); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/OrderAction.java b/openmessaging-api/src/main/java/io/openmessaging/order/OrderAction.java new file mode 100644 index 00000000..7b6e6de8 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/order/OrderAction.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.order; + + +public enum OrderAction { + + Success, + + Suspend, +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/OrderConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/order/OrderConsumer.java new file mode 100644 index 00000000..fb565d5b --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/order/OrderConsumer.java @@ -0,0 +1,29 @@ +/* + * 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.order; + +import io.openmessaging.Credentials; +import io.openmessaging.LifeCycle; +import io.openmessaging.MessageSelector; + +public interface OrderConsumer extends LifeCycle, Credentials { + + void subscribe(final String topic, final String subExpression, final MessageOrderListener listener); + + void subscribe(final String topic, final MessageSelector selector, final MessageOrderListener listener); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/OrderProducer.java b/openmessaging-api/src/main/java/io/openmessaging/order/OrderProducer.java new file mode 100644 index 00000000..59274312 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/order/OrderProducer.java @@ -0,0 +1,28 @@ +/* + * 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.order; + +import io.openmessaging.Credentials; +import io.openmessaging.LifeCycle; +import io.openmessaging.Message; +import io.openmessaging.SendResult; + +public interface OrderProducer extends LifeCycle, Credentials { + + SendResult send(final Message message, final String shardingKey); +} 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/main/java/io/openmessaging/transaction/LocalTransactionChecker.java b/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionChecker.java new file mode 100644 index 00000000..97808dca --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionChecker.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.transaction; + +import io.openmessaging.Message; + +public interface LocalTransactionChecker { + + TransactionStatus check(final Message msg); + + +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionExecutor.java b/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionExecutor.java new file mode 100644 index 00000000..b40d49a8 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionExecutor.java @@ -0,0 +1,25 @@ +/* + * 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.transaction; + +import io.openmessaging.Message; + +public interface LocalTransactionExecutor { + + TransactionStatus execute(final Message message, final Object arg); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionProducer.java b/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionProducer.java new file mode 100644 index 00000000..4ed49182 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionProducer.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.transaction; + +import io.openmessaging.Credentials; +import io.openmessaging.LifeCycle; +import io.openmessaging.Message; +import io.openmessaging.SendResult; + +public interface TransactionProducer extends LifeCycle, Credentials { + + SendResult send(final Message message, + final LocalTransactionExecutor localTransactionExecutor, + final Object arg); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionStatus.java b/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionStatus.java new file mode 100644 index 00000000..caad6f24 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionStatus.java @@ -0,0 +1,28 @@ +/* + * 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.transaction; + + +public enum TransactionStatus { + + CommitTransaction, + + RollbackTransaction, + + Unknown +} 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 index b348996e..c02b20e0 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java @@ -17,17 +17,18 @@ package io.openmessaging.internal; -import io.openmessaging.KeyValue; +import io.openmessaging.Consumer; 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 io.openmessaging.Producer; +import io.openmessaging.PullConsumer; +import io.openmessaging.batch.BatchConsumer; +import io.openmessaging.order.OrderConsumer; +import io.openmessaging.order.OrderProducer; +import io.openmessaging.transaction.LocalTransactionChecker; +import io.openmessaging.transaction.TransactionProducer; +import java.util.Properties; import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -37,65 +38,49 @@ public class MessagingAccessPointAdapterTest { 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); + Properties properties = new Properties(); + properties.put(OMSBuiltinKeys.DRIVER_IMPL, "io.openmessaging.internal.TestVendor"); + MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint(testURI, properties); assertThat(messagingAccessPoint).isExactlyInstanceOf(TestVendor.class); } } class TestVendor implements MessagingAccessPoint { - public TestVendor(KeyValue keyValue) { - } - - @Override - public Producer createProducer(TransactionStateCheckListener transactionStateCheckListener) { + @Override public String version() { return null; } - @Override - public PushConsumer createPushConsumer() { + @Override public Properties attributes() { return null; } - @Override - public PullConsumer createPullConsumer() { + @Override public Producer createProducer(Properties properties) { return null; } - @Override - public PushConsumer createPushConsumer(KeyValue attributes) { + @Override public OrderProducer createOrderProducer(Properties properties) { return null; } - @Override - public PullConsumer createPullConsumer(KeyValue attributes) { + @Override public TransactionProducer createTransactionProducer(Properties properties, + LocalTransactionChecker checker) { return null; } - @Override - public MessageFactory messageFactory() { + @Override public Consumer createConsumer(Properties properties) { return null; } - @Override - public String version() { - return OMS.specVersion; - } - - @Override - public KeyValue attributes() { + @Override public PullConsumer createPullConsumer(Properties properties) { return null; } - @Override - public Producer createProducer() { + @Override public BatchConsumer createBatchConsumer(Properties properties) { return null; } - @Override - public ResourceManager resourceManager() { + @Override public OrderConsumer createOrderedConsumer(Properties properties) { return null; } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0ef1d346..fc123e50 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 1.0.0-beta-SNAPSHOT + 1.1.0-SNAPSHOT pom openmessaging From e0ea306b94f0e945425c8784d5b8db146f14212e Mon Sep 17 00:00:00 2001 From: duhenglucky Date: Tue, 3 Sep 2019 20:09:21 +0800 Subject: [PATCH 02/23] Add MessagingAccessPointAdapterTest --- .../internal/MessagingAccessPointAdapterTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java b/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java index c02b20e0..32dc59a9 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java @@ -46,9 +46,12 @@ public void getMessagingAccessPoint() { } class TestVendor implements MessagingAccessPoint { + public TestVendor(Properties properties) { + + } @Override public String version() { - return null; + return "1.1.3"; } @Override public Properties attributes() { From e24117adb86d56a2efff012c659a87df86f680a2 Mon Sep 17 00:00:00 2001 From: duhenglucky Date: Tue, 12 Nov 2019 20:46:16 +0800 Subject: [PATCH 03/23] feat(api) polish openmessaging api definition --- .../samples/consumer/PullConsumerApp.java | 10 +- .../samples/consumer/PushConsumerApp.java | 16 +- .../samples/producer/ProducerApp.java | 16 +- .../producer/TransactionProducerApp.java | 16 +- .../io/openmessaging/{ => api}/Action.java | 2 +- .../io/openmessaging/{ => api}/Constants.java | 2 +- .../{ => api}/ConsumeContext.java | 2 +- .../io/openmessaging/{ => api}/Consumer.java | 2 +- .../openmessaging/{ => api}/Credentials.java | 2 +- .../{ => api}/ExpressionType.java | 2 +- .../io/openmessaging/{ => api}/Future.java | 2 +- .../{ => api}/FutureListener.java | 2 +- .../io/openmessaging/{ => api}/LifeCycle.java | 2 +- .../io/openmessaging/{ => api}/Message.java | 2 +- .../{ => api}/MessageAccessor.java | 2 +- .../{ => api}/MessageListener.java | 2 +- .../{ => api}/MessageSelector.java | 2 +- .../{ => api}/MessagingAccessPoint.java | 14 +- .../java/io/openmessaging/{ => api}/OMS.java | 8 +- .../{ => api}/OMSBuiltinKeys.java | 13 +- .../{ => api}/OMSResponseStatus.java | 4 +- .../java/io/openmessaging/api/ONSFactory.java | 197 ++++++++++++++++++ .../io/openmessaging/api/ONSFactoryAPI.java | 33 +++ .../{ => api}/OnExceptionContext.java | 4 +- .../io/openmessaging/{ => api}/Producer.java | 2 +- .../openmessaging/api/PropertyKeyConst.java | 74 +++++++ .../{ => api}/PropertyValueConst.java | 2 +- .../openmessaging/{ => api}/PullConsumer.java | 2 +- .../openmessaging/{ => api}/SendCallback.java | 2 +- .../openmessaging/{ => api}/SendResult.java | 2 +- .../io/openmessaging/api/ServiceProvider.java | 144 +++++++++++++ .../{ => api}/TopicPartition.java | 2 +- .../{ => api}/batch/BatchConsumer.java | 6 +- .../{ => api}/batch/BatchMessageListener.java | 8 +- .../{ => api}/bean/Subscription.java | 4 +- .../{ => api}/bean/SubscriptionExt.java | 2 +- .../exception/OMSDestinationException.java | 2 +- .../exception/OMSMessageFormatException.java | 2 +- .../exception/OMSRuntimeException.java | 4 +- .../exception/OMSSecurityException.java | 2 +- .../exception/OMSTimeOutException.java | 2 +- .../exception/OMSTransactionException.java | 2 +- .../exception/OMSUnsupportException.java | 2 +- .../{ => api}/internal/AccessPointURI.java | 6 +- .../internal/MessagingAccessPointAdapter.java | 14 +- .../{ => api}/order/ConsumeOrderContext.java | 2 +- .../{ => api}/order/MessageOrderListener.java | 4 +- .../{ => api}/order/MessageQueueSelector.java | 4 +- .../{ => api}/order/OrderAction.java | 2 +- .../{ => api}/order/OrderConsumer.java | 8 +- .../{ => api}/order/OrderProducer.java | 10 +- .../transaction/LocalTransactionChecker.java | 4 +- .../transaction/LocalTransactionExecutor.java | 4 +- .../transaction/TransactionProducer.java | 10 +- .../transaction/TransactionStatus.java | 2 +- .../internal/AccessPointURITest.java | 4 +- .../internal/InternalErrorCodeTest.java | 6 +- .../MessagingAccessPointAdapterTest.java | 32 +-- pom.xml | 2 +- 59 files changed, 593 insertions(+), 144 deletions(-) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/Action.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/Constants.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/ConsumeContext.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/Consumer.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/Credentials.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/ExpressionType.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/Future.java (99%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/FutureListener.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/LifeCycle.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/Message.java (99%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/MessageAccessor.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/MessageListener.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/MessageSelector.java (98%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/MessagingAccessPoint.java (93%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/OMS.java (94%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/OMSBuiltinKeys.java (89%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/OMSResponseStatus.java (98%) create mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/ONSFactory.java create mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/OnExceptionContext.java (94%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/Producer.java (97%) create mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/PropertyValueConst.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/PullConsumer.java (99%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/SendCallback.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/SendResult.java (97%) create mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/TopicPartition.java (98%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/batch/BatchConsumer.java (89%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/batch/BatchMessageListener.java (86%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/bean/Subscription.java (96%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/bean/SubscriptionExt.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/exception/OMSDestinationException.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/exception/OMSMessageFormatException.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/exception/OMSRuntimeException.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/exception/OMSSecurityException.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/exception/OMSTimeOutException.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/exception/OMSTransactionException.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/exception/OMSUnsupportException.java (97%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/internal/AccessPointURI.java (95%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/internal/MessagingAccessPointAdapter.java (91%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/order/ConsumeOrderContext.java (95%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/order/MessageOrderListener.java (92%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/order/MessageQueueSelector.java (92%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/order/OrderAction.java (95%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/order/OrderConsumer.java (87%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/order/OrderProducer.java (82%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/transaction/LocalTransactionChecker.java (91%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/transaction/LocalTransactionExecutor.java (92%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/transaction/TransactionProducer.java (83%) rename openmessaging-api/src/main/java/io/openmessaging/{ => api}/transaction/TransactionStatus.java (95%) rename openmessaging-api/src/test/java/io/openmessaging/{ => api}/internal/AccessPointURITest.java (97%) rename openmessaging-api/src/test/java/io/openmessaging/{ => api}/internal/InternalErrorCodeTest.java (90%) rename openmessaging-api/src/test/java/io/openmessaging/{ => api}/internal/MessagingAccessPointAdapterTest.java (78%) 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 01ce66d2..8d8c3c2a 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,11 +17,11 @@ package io.openmessaging.samples.consumer; -import io.openmessaging.Message; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.PullConsumer; -import io.openmessaging.TopicPartition; +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.time.Duration; import java.util.List; import java.util.Properties; 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 023957f2..f370a8cf 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,20 +17,20 @@ package io.openmessaging.samples.consumer; -import io.openmessaging.Action; -import io.openmessaging.ConsumeContext; -import io.openmessaging.Consumer; -import io.openmessaging.Message; -import io.openmessaging.MessageListener; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; +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.getMessagingAccessPoint("oms:rocketmq://localhost:9876"); Properties properties = new Properties(); final Consumer consumer = messagingAccessPoint.createConsumer(properties); 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 a16d9cd5..bcde63f1 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,19 +17,19 @@ package io.openmessaging.samples.producer; -import io.openmessaging.Message; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.OnExceptionContext; -import io.openmessaging.Producer; -import io.openmessaging.SendCallback; -import io.openmessaging.SendResult; +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.getMessagingAccessPoint("oms:rocketmq://alice@rocketmq.apache.org"); final Producer producer = messagingAccessPoint.createProducer(new Properties()); producer.start(); 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 d8cb1f4d..d492946d 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,14 +17,14 @@ package io.openmessaging.samples.producer; -import io.openmessaging.Message; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.SendResult; -import io.openmessaging.transaction.LocalTransactionChecker; -import io.openmessaging.transaction.LocalTransactionExecutor; -import io.openmessaging.transaction.TransactionProducer; -import io.openmessaging.transaction.TransactionStatus; +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.LocalTransactionExecutor; +import io.openmessaging.api.transaction.TransactionProducer; +import io.openmessaging.api.transaction.TransactionStatus; import java.util.Properties; public class TransactionProducerApp { diff --git a/openmessaging-api/src/main/java/io/openmessaging/Action.java b/openmessaging-api/src/main/java/io/openmessaging/api/Action.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/Action.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Action.java index 4982b002..851163fc 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Action.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Action.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public enum Action { diff --git a/openmessaging-api/src/main/java/io/openmessaging/Constants.java b/openmessaging-api/src/main/java/io/openmessaging/api/Constants.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/Constants.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Constants.java index cdbdee21..e436c455 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Constants.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Constants.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public class Constants { public static final String TRANSACTION_ID = "__transactionId__"; diff --git a/openmessaging-api/src/main/java/io/openmessaging/ConsumeContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/ConsumeContext.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/ConsumeContext.java rename to openmessaging-api/src/main/java/io/openmessaging/api/ConsumeContext.java index c49b06bb..e2f9996a 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/ConsumeContext.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ConsumeContext.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public class ConsumeContext { diff --git a/openmessaging-api/src/main/java/io/openmessaging/Consumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java similarity index 97% rename from openmessaging-api/src/main/java/io/openmessaging/Consumer.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java index a06c265a..9e6c901e 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Consumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public interface Consumer extends LifeCycle, Credentials { diff --git a/openmessaging-api/src/main/java/io/openmessaging/Credentials.java b/openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/Credentials.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java index cb94a742..41eca294 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Credentials.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; import java.util.Properties; public interface Credentials { diff --git a/openmessaging-api/src/main/java/io/openmessaging/ExpressionType.java b/openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/ExpressionType.java rename to openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java index 4cd89a36..4bb3712d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/ExpressionType.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public enum ExpressionType { 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 99% rename from openmessaging-api/src/main/java/io/openmessaging/Future.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Future.java index ff57d01d..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; /** *

    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 97% rename from openmessaging-api/src/main/java/io/openmessaging/FutureListener.java rename to openmessaging-api/src/main/java/io/openmessaging/api/FutureListener.java index 767df010..06010cfa 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/FutureListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/FutureListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; /** * A listener that is called back when a Promise is done. diff --git a/openmessaging-api/src/main/java/io/openmessaging/LifeCycle.java b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/LifeCycle.java rename to openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java index b4d4ec32..8a1ffe54 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/LifeCycle.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public interface LifeCycle { boolean isStarted(); diff --git a/openmessaging-api/src/main/java/io/openmessaging/Message.java b/openmessaging-api/src/main/java/io/openmessaging/api/Message.java similarity index 99% rename from openmessaging-api/src/main/java/io/openmessaging/Message.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Message.java index 84a93360..eb39c33c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Message.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Message.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; import java.io.Serializable; import java.util.Properties; diff --git a/openmessaging-api/src/main/java/io/openmessaging/MessageAccessor.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java similarity index 97% rename from openmessaging-api/src/main/java/io/openmessaging/MessageAccessor.java rename to openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java index 3b67e4d3..ff8fbdfa 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/MessageAccessor.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; import java.util.Properties; diff --git a/openmessaging-api/src/main/java/io/openmessaging/MessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/MessageListener.java rename to openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java index 1788973a..db6fdd40 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/MessageListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public interface MessageListener { diff --git a/openmessaging-api/src/main/java/io/openmessaging/MessageSelector.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessageSelector.java similarity index 98% rename from openmessaging-api/src/main/java/io/openmessaging/MessageSelector.java rename to openmessaging-api/src/main/java/io/openmessaging/api/MessageSelector.java index ca6cc77e..37bde240 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/MessageSelector.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageSelector.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public class MessageSelector { 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 93% rename from openmessaging-api/src/main/java/io/openmessaging/MessagingAccessPoint.java rename to openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java index a7ca1022..4c297847 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/MessagingAccessPoint.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java @@ -15,15 +15,13 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; -import io.openmessaging.batch.BatchConsumer; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.exception.OMSSecurityException; -import io.openmessaging.order.OrderConsumer; -import io.openmessaging.order.OrderProducer; -import io.openmessaging.transaction.LocalTransactionChecker; -import io.openmessaging.transaction.TransactionProducer; +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; /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/OMS.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java similarity index 94% rename from openmessaging-api/src/main/java/io/openmessaging/OMS.java rename to openmessaging-api/src/main/java/io/openmessaging/api/OMS.java index ba88c8b0..5d387fce 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMS.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; -import io.openmessaging.exception.OMSRuntimeException; -import io.openmessaging.internal.MessagingAccessPointAdapter; +import io.openmessaging.api.exception.OMSRuntimeException; +import io.openmessaging.api.internal.MessagingAccessPointAdapter; import java.io.IOException; import java.io.InputStream; import java.util.Properties; @@ -31,7 +31,7 @@ *

    * {@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 first part of the URL specifies which OMS implementation is to be used, rocketmq is an 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. 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 89% rename from openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java rename to openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java index 37084672..de20eea5 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OMSBuiltinKeys.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java @@ -15,24 +15,25 @@ * 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.1.0 - * @since OMS 1.1.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"; /** * The {@code ACCESS_POINTS} key shows the specified access points in OMS driver schema. - * @see Access Point Schema + * + * @see Access Point + * Schema */ String ACCESS_POINTS = "ACCESS_POINTS"; 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/ONSFactory.java b/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactory.java new file mode 100644 index 00000000..65339711 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactory.java @@ -0,0 +1,197 @@ +package io.openmessaging.api; + +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; + +/** + * {@link OMS} is recommended. + */ +@Deprecated +public class ONSFactory { + + private static ONSFactoryAPI onsFactory; + + static { + onsFactory = (ONSFactoryAPI) ServiceProvider.load(ServiceProvider.OMS_DRIVER, ONSFactoryAPI.class).get(0); + } + + /** + * Create Producer + * + *

    + * properties + * Require: + *

      + *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. + *
    3. {@link PropertyKeyConst#AccessKey}
    4. + *
    5. {@link PropertyKeyConst#SecretKey}
    6. + *
    7. {@link PropertyKeyConst#ONSAddr}
    8. + *
    + * Optional: + *
      + *
    1. {@link PropertyKeyConst#OnsChannel}
    2. + *
    3. {@link PropertyKeyConst#SendMsgTimeoutMillis}
    4. + *
    5. {@link PropertyKeyConst#NAMESRV_ADDR} will override {@link PropertyKeyConst#ONSAddr}
    6. + *
    + *

    + * + * + *

    + * sample: + *

    +     *        Properties props = ...;
    +     *        Producer producer = ONSFactory.createProducer(props);
    +     *        producer.start();
    +     *
    +     *
    +     *        Message msg = ...;
    +     *        SendResult result = producer.send(msg);
    +     *
    +     *        producer.shutdown();
    +     *   
    + *

    + * + * @param properties Producer's configuration + * @return {@link Producer} Thread safe {@link Producer} instance + */ + public static Producer createProducer(final Properties properties) { + return onsFactory.createProducer(properties); + } + + /** + * Create OrderProducer + *

    + * properties + * Require: + *

      + *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. + *
    3. {@link PropertyKeyConst#AccessKey}
    4. + *
    5. {@link PropertyKeyConst#SecretKey}
    6. + *
    7. {@link PropertyKeyConst#ONSAddr}
    8. + *
    + * Optional: + *
      + *
    • {@link PropertyKeyConst#NAMESRV_ADDR}
    • + *
    • {@link PropertyKeyConst#OnsChannel}
    • + *
    • {@link PropertyKeyConst#SendMsgTimeoutMillis}
    • + *
    + *

    + * + * @param properties Producer configuration + * @return {@code OrderProducer} Thread safe {@link OrderProducer} instance + */ + public static OrderProducer createOrderProducer(final Properties properties) { + return onsFactory.createOrderProducer(properties); + } + + /** + * Create Transaction Producer + *

    + * propertiesRequires: + *

      + *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. + *
    3. {@link PropertyKeyConst#AccessKey}
    4. + *
    5. {@link PropertyKeyConst#SecretKey}
    6. + *
    7. {@link PropertyKeyConst#ONSAddr}
    8. + *
    + * Optional: + *
      + *
    • {@link PropertyKeyConst#NAMESRV_ADDR}
    • + *
    • {@link PropertyKeyConst#OnsChannel}
    • + *
    • {@link PropertyKeyConst#SendMsgTimeoutMillis}
    • + *
    • {@link PropertyKeyConst#CheckImmunityTimeInSeconds}
    • + *
    + *

    + * + * @param properties Producer configuration + * @return {@code TransactionProducer} Thread safe {@link TransactionProducer} instance + */ + public static TransactionProducer createTransactionProducer(final Properties properties, + final LocalTransactionChecker checker) { + return onsFactory.createTransactionProducer(properties, checker); + } + + /** + * Create Consumer + *

    + * properties + * Requires: + *

      + *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. + *
    3. {@link PropertyKeyConst#AccessKey}
    4. + *
    5. {@link PropertyKeyConst#SecretKey}
    6. + *
    7. {@link PropertyKeyConst#ONSAddr}
    8. + *
    + * Optional: + *
      + *
    • {@link PropertyKeyConst#ConsumeThreadNums}
    • + *
    • {@link PropertyKeyConst#ConsumeTimeout}
    • + *
    • {@link PropertyKeyConst#OnsChannel}
    • + *
    + *

    + * + * @param properties Consumer's configuration + * @return {@code Consumer} Thread safe {@link Consumer} instance + */ + public static Consumer createConsumer(final Properties properties) { + return onsFactory.createConsumer(properties); + } + + /** + * Create BatchConsumer + *

    + * properties + * Requires: + *

      + *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. + *
    3. {@link PropertyKeyConst#AccessKey}
    4. + *
    5. {@link PropertyKeyConst#SecretKey}
    6. + *
    7. {@link PropertyKeyConst#ONSAddr}
    8. + *
    + * Optional: + *
      + *
    • {@link PropertyKeyConst#ConsumeThreadNums}
    • + *
    • {@link PropertyKeyConst#ConsumeTimeout}
    • + *
    • {@link PropertyKeyConst#ConsumeMessageBatchMaxSize}
    • + *
    • {@link PropertyKeyConst#OnsChannel}
    • + *
    + *

    + * + * @param properties BatchConsumer's configuration + * @return {@code BatchConsumer} Thread safe {@link BatchConsumer} instance + */ + public static BatchConsumer createBatchConsumer(final Properties properties) { + return onsFactory.createBatchConsumer(properties); + } + + /** + * Create Order Consumer + *

    + * properties + * Requires: + *

      + *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. + *
    3. {@link PropertyKeyConst#AccessKey}
    4. + *
    5. {@link PropertyKeyConst#SecretKey}
    6. + *
    7. {@link PropertyKeyConst#ONSAddr}
    8. + *
    + * Optional: + *
      + *
    • {@link PropertyKeyConst#ConsumeThreadNums}
    • + *
    • {@link PropertyKeyConst#ConsumeTimeout}
    • + *
    • {@link PropertyKeyConst#OnsChannel}
    • + *
    + *

    + * + * @param properties Consumer's configuration + * @return {@code OrderConsumer} Thread safe {@link OrderConsumer} instance + */ + public static OrderConsumer createOrderedConsumer(final Properties properties) { + return onsFactory.createOrderedConsumer(properties); + } + +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java b/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java new file mode 100644 index 00000000..f249dc55 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java @@ -0,0 +1,33 @@ +package io.openmessaging.api; + +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; + +/** + * {@link MessagingAccessPoint} is recommended. + */ +@Deprecated +public interface ONSFactoryAPI { + + Producer createProducer(final Properties properties); + + + Consumer createConsumer(final Properties properties); + + + BatchConsumer createBatchConsumer(final Properties properties); + + + OrderProducer createOrderProducer(final Properties properties); + + + OrderConsumer createOrderedConsumer(final Properties properties); + + + TransactionProducer createTransactionProducer(final Properties properties, + final LocalTransactionChecker checker); +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/OnExceptionContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java similarity index 94% rename from openmessaging-api/src/main/java/io/openmessaging/OnExceptionContext.java rename to openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java index 145ed300..49b5800d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/OnExceptionContext.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; -import io.openmessaging.exception.OMSRuntimeException; +import io.openmessaging.api.exception.OMSRuntimeException; public class OnExceptionContext { diff --git a/openmessaging-api/src/main/java/io/openmessaging/Producer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java similarity index 97% rename from openmessaging-api/src/main/java/io/openmessaging/Producer.java rename to openmessaging-api/src/main/java/io/openmessaging/api/Producer.java index 27c76bb6..5e7fdcee 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/Producer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; import java.util.concurrent.ExecutorService; diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java b/openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java new file mode 100644 index 00000000..58e616b6 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java @@ -0,0 +1,74 @@ +/* + * 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 PropertyKeyConst implements OMSBuiltinKeys { + + public static final String MessageModel = "MessageModel"; + + public static final String GROUP_ID = "GROUP_ID"; + + public static final String AccessKey = "AccessKey"; + + public static final String SecretKey = "SecretKey"; + + public static final String SecurityToken = "SecurityToken"; + + public static final String SendMsgTimeoutMillis = "SendMsgTimeoutMillis"; + + @Deprecated + public static final String ONSAddr = "ONSAddr"; + + @Deprecated + public static final String NAMESRV_ADDR = "NAMESRV_ADDR"; + + public static final String ConsumeThreadNums = "ConsumeThreadNums"; + + public static final String OnsChannel = "OnsChannel"; + + public static final String MQType = "MQType"; + + public static final String isVipChannelEnabled = "isVipChannelEnabled"; + + public static final String SuspendTimeMillis = "suspendTimeMillis"; + + public static final String MaxReconsumeTimes = "maxReconsumeTimes"; + + public static final String ConsumeTimeout = "consumeTimeout"; + + public static final String CheckImmunityTimeInSeconds = "CheckImmunityTimeInSeconds"; + + public static final String PostSubscriptionWhenPull = "PostSubscriptionWhenPull"; + + public static final String ConsumeMessageBatchMaxSize = "ConsumeMessageBatchMaxSize"; + + public static final String MaxCachedMessageAmount = "maxCachedMessageAmount"; + + public static final String MaxCachedMessageSizeInMiB = "maxCachedMessageSizeInMiB"; + + public static final String InstanceName = "InstanceName"; + + @Deprecated + public static final String EXACTLYONCE_DELIVERY = "exactlyOnceDelivery"; + + public static final String QOS = "qos"; + + public static final String EXACTLYONCE_RM_REFRESHINTERVAL = "exactlyOnceRmRefreshInterval"; + + public static final String MAX_BATCH_MESSAGE_COUNT = "maxBatchMessageCount"; + +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/PropertyValueConst.java b/openmessaging-api/src/main/java/io/openmessaging/api/PropertyValueConst.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/PropertyValueConst.java rename to openmessaging-api/src/main/java/io/openmessaging/api/PropertyValueConst.java index 3a1e7b07..1a990808 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/PropertyValueConst.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/PropertyValueConst.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public class PropertyValueConst { diff --git a/openmessaging-api/src/main/java/io/openmessaging/PullConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java similarity index 99% rename from openmessaging-api/src/main/java/io/openmessaging/PullConsumer.java rename to openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java index 21fa8304..ff809d92 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/PullConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; import java.time.Duration; import java.util.Collection; diff --git a/openmessaging-api/src/main/java/io/openmessaging/SendCallback.java b/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/SendCallback.java rename to openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java index 0c79e626..168abf0d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/SendCallback.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public interface SendCallback { diff --git a/openmessaging-api/src/main/java/io/openmessaging/SendResult.java b/openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java similarity index 97% rename from openmessaging-api/src/main/java/io/openmessaging/SendResult.java rename to openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java index aff1b888..94458334 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/SendResult.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public class SendResult { diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java b/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java new file mode 100644 index 00000000..da478027 --- /dev/null +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java @@ -0,0 +1,144 @@ +/** + * 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.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +public class ServiceProvider { + + /** + * A reference to the classloader that loaded this class. It's more efficient to compute it once and cache it here. + */ + private static ClassLoader thisClassLoader; + + /** + * JDK1.3+ 'Service Provider' specification. + */ + public static final String OMS_DRIVER = "META-INF/service/io.openmessaging.api.ONSFactoryAPI"; + + static { + thisClassLoader = getClassLoader(ServiceProvider.class); + } + + /** + * Returns a string that uniquely identifies the specified object, including its class. + *

    + * The returned string is of form "classname@hashcode", ie is the same as the return value of the Object.toString() method, but works even when the specified object's class has overidden the toString method. + * + * @param o may be null. + * @return a string of form classname@hashcode, or "null" if param o is null. + */ + protected static String objectId(Object o) { + if (o == null) { + return "null"; + } else { + return o.getClass().getName() + "@" + System.identityHashCode(o); + } + } + + protected static ClassLoader getClassLoader(Class clazz) { + try { + return clazz.getClassLoader(); + } catch (SecurityException e) { + throw e; + } + } + + protected static ClassLoader getContextClassLoader() { + ClassLoader classLoader = null; + try { + classLoader = Thread.currentThread().getContextClassLoader(); + } catch (SecurityException ex) { + /** + * The getContextClassLoader() method throws SecurityException when the context + * class loader isn't an ancestor of the calling class's class + * loader, or if security permissions are restricted. + */ + } + return classLoader; + } + + protected static InputStream getResourceAsStream(ClassLoader loader, String name) { + if (loader != null) { + return loader.getResourceAsStream(name); + } else { + return ClassLoader.getSystemResourceAsStream(name); + } + } + + public static List load(String name, Class clazz) { + List services = new ArrayList(); + try { + ArrayList names = new ArrayList(); + final InputStream is = getResourceAsStream(getContextClassLoader(), name); + if (is != null) { + BufferedReader reader; + try { + reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); + } catch (java.io.UnsupportedEncodingException e) { + reader = new BufferedReader(new InputStreamReader(is)); + } + String serviceName = reader.readLine(); + while (serviceName != null && !"".equals(serviceName)) { + if (!names.contains(serviceName)) { + names.add(serviceName); + } + + services.add((T) initService(getContextClassLoader(), serviceName, clazz)); + + serviceName = reader.readLine(); + } + reader.close(); + } else { + // is == null + } + } catch (Exception e) { + } + return services; + } + + protected static T initService(ClassLoader classLoader, String serviceName, Class clazz) { + Class serviceClazz = null; + try { + if (classLoader != null) { + try { + // Warning: must typecast here & allow exception to be generated/caught & recast properly + serviceClazz = classLoader.loadClass(serviceName); + if (clazz.isAssignableFrom(serviceClazz)) { + + } else { + + } + return (T) serviceClazz.newInstance(); + } catch (ClassNotFoundException ex) { + if (classLoader == thisClassLoader) { + // Nothing more to try, onwards. + throw ex; + } + // Ignore exception, continue + } catch (NoClassDefFoundError e) { + if (classLoader == thisClassLoader) { + throw e; + } + // Ignore exception, continue + } + } + } catch (Exception e) { + } + return (T) serviceClazz; + } +} diff --git a/openmessaging-api/src/main/java/io/openmessaging/TopicPartition.java b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java similarity index 98% rename from openmessaging-api/src/main/java/io/openmessaging/TopicPartition.java rename to openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java index 88668061..34c226e6 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/TopicPartition.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging; +package io.openmessaging.api; public class TopicPartition { private String topic; diff --git a/openmessaging-api/src/main/java/io/openmessaging/batch/BatchConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java similarity index 89% rename from openmessaging-api/src/main/java/io/openmessaging/batch/BatchConsumer.java rename to openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java index 1cd6072f..baeef0f4 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/batch/BatchConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java @@ -15,10 +15,10 @@ * limitations under the License. */ -package io.openmessaging.batch; +package io.openmessaging.api.batch; -import io.openmessaging.Credentials; -import io.openmessaging.LifeCycle; +import io.openmessaging.api.Credentials; +import io.openmessaging.api.LifeCycle; public interface BatchConsumer extends LifeCycle, Credentials { diff --git a/openmessaging-api/src/main/java/io/openmessaging/batch/BatchMessageListener.java b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java similarity index 86% rename from openmessaging-api/src/main/java/io/openmessaging/batch/BatchMessageListener.java rename to openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java index ca3adb98..3a0e44ca 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/batch/BatchMessageListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package io.openmessaging.batch; +package io.openmessaging.api.batch; -import io.openmessaging.Action; -import io.openmessaging.ConsumeContext; -import io.openmessaging.Message; +import io.openmessaging.api.Action; +import io.openmessaging.api.ConsumeContext; +import io.openmessaging.api.Message; import java.util.List; diff --git a/openmessaging-api/src/main/java/io/openmessaging/bean/Subscription.java b/openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java similarity index 96% rename from openmessaging-api/src/main/java/io/openmessaging/bean/Subscription.java rename to openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java index 523fda3e..7253342e 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/bean/Subscription.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package io.openmessaging.bean; +package io.openmessaging.api.bean; -import io.openmessaging.ExpressionType; +import io.openmessaging.api.ExpressionType; public class Subscription { private String topic; diff --git a/openmessaging-api/src/main/java/io/openmessaging/bean/SubscriptionExt.java b/openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java similarity index 97% rename from openmessaging-api/src/main/java/io/openmessaging/bean/SubscriptionExt.java rename to openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java index 1d173293..2fb52769 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/bean/SubscriptionExt.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package io.openmessaging.bean; +package io.openmessaging.api.bean; public class SubscriptionExt extends Subscription { 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 97% 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 5f6919dd..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,7 +15,7 @@ * 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 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 97% 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 3175449e..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,7 +15,7 @@ * 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 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 97% 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 d93f68a5..46cefb05 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,9 +15,9 @@ * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; -import io.openmessaging.OMSResponseStatus; +import io.openmessaging.api.OMSResponseStatus; /** * This is the root class of all unchecked exceptions in the OMS API. 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 97% 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 91550cd8..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,7 +15,7 @@ * 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. 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 97% 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 72b0b690..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,7 +15,7 @@ * 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. 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 97% 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 a05713f3..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,7 +15,7 @@ * 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. 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 97% 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 f6a698f1..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,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging.exception; +package io.openmessaging.api.exception; /** diff --git a/openmessaging-api/src/main/java/io/openmessaging/internal/AccessPointURI.java b/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/internal/AccessPointURI.java rename to openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java index 52336b91..be7cbd15 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/internal/AccessPointURI.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package io.openmessaging.internal; +package io.openmessaging.api.internal; -import io.openmessaging.OMSResponseStatus; +import io.openmessaging.api.OMSResponseStatus; -import static io.openmessaging.OMSResponseStatus.generateException; +import static io.openmessaging.api.OMSResponseStatus.generateException; /** * Represents a AccessPoint String. 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 91% 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 0b5f8bd8..af2f1834 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,17 +15,17 @@ * limitations under the License. */ -package io.openmessaging.internal; +package io.openmessaging.api.internal; -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.OMS; +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 diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/ConsumeOrderContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/ConsumeOrderContext.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/order/ConsumeOrderContext.java rename to openmessaging-api/src/main/java/io/openmessaging/api/order/ConsumeOrderContext.java index 2143b1df..fe4884d3 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/order/ConsumeOrderContext.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/ConsumeOrderContext.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging.order; +package io.openmessaging.api.order; public class ConsumeOrderContext { diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/MessageOrderListener.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java similarity index 92% rename from openmessaging-api/src/main/java/io/openmessaging/order/MessageOrderListener.java rename to openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java index 5c9f7c4f..0896ba50 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/order/MessageOrderListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package io.openmessaging.order; +package io.openmessaging.api.order; -import io.openmessaging.Message; +import io.openmessaging.api.Message; public interface MessageOrderListener { diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/MessageQueueSelector.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageQueueSelector.java similarity index 92% rename from openmessaging-api/src/main/java/io/openmessaging/order/MessageQueueSelector.java rename to openmessaging-api/src/main/java/io/openmessaging/api/order/MessageQueueSelector.java index b8684988..df57586c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/order/MessageQueueSelector.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageQueueSelector.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package io.openmessaging.order; +package io.openmessaging.api.order; -import io.openmessaging.Message; +import io.openmessaging.api.Message; public interface MessageQueueSelector { diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/OrderAction.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/order/OrderAction.java rename to openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.java index 7b6e6de8..075c7c0e 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/order/OrderAction.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package io.openmessaging.order; +package io.openmessaging.api.order; public enum OrderAction { diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/OrderConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java similarity index 87% rename from openmessaging-api/src/main/java/io/openmessaging/order/OrderConsumer.java rename to openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java index fb565d5b..70c5afee 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/order/OrderConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package io.openmessaging.order; +package io.openmessaging.api.order; -import io.openmessaging.Credentials; -import io.openmessaging.LifeCycle; -import io.openmessaging.MessageSelector; +import io.openmessaging.api.Credentials; +import io.openmessaging.api.LifeCycle; +import io.openmessaging.api.MessageSelector; public interface OrderConsumer extends LifeCycle, Credentials { diff --git a/openmessaging-api/src/main/java/io/openmessaging/order/OrderProducer.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java similarity index 82% rename from openmessaging-api/src/main/java/io/openmessaging/order/OrderProducer.java rename to openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java index 59274312..e74302f0 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/order/OrderProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package io.openmessaging.order; +package io.openmessaging.api.order; -import io.openmessaging.Credentials; -import io.openmessaging.LifeCycle; -import io.openmessaging.Message; -import io.openmessaging.SendResult; +import io.openmessaging.api.Credentials; +import io.openmessaging.api.LifeCycle; +import io.openmessaging.api.Message; +import io.openmessaging.api.SendResult; public interface OrderProducer extends LifeCycle, Credentials { diff --git a/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionChecker.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java similarity index 91% rename from openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionChecker.java rename to openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java index 97808dca..d69d548d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionChecker.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.openmessaging.transaction; +package io.openmessaging.api.transaction; -import io.openmessaging.Message; +import io.openmessaging.api.Message; public interface LocalTransactionChecker { diff --git a/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionExecutor.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java similarity index 92% rename from openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionExecutor.java rename to openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java index b40d49a8..0da501fb 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/transaction/LocalTransactionExecutor.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package io.openmessaging.transaction; +package io.openmessaging.api.transaction; -import io.openmessaging.Message; +import io.openmessaging.api.Message; public interface LocalTransactionExecutor { diff --git a/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionProducer.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java similarity index 83% rename from openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionProducer.java rename to openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java index 4ed49182..2f1b0d2c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package io.openmessaging.transaction; +package io.openmessaging.api.transaction; -import io.openmessaging.Credentials; -import io.openmessaging.LifeCycle; -import io.openmessaging.Message; -import io.openmessaging.SendResult; +import io.openmessaging.api.Credentials; +import io.openmessaging.api.LifeCycle; +import io.openmessaging.api.Message; +import io.openmessaging.api.SendResult; public interface TransactionProducer extends LifeCycle, Credentials { diff --git a/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionStatus.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java similarity index 95% rename from openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionStatus.java rename to openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java index caad6f24..70a3d636 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/transaction/TransactionStatus.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package io.openmessaging.transaction; +package io.openmessaging.api.transaction; public enum TransactionStatus { diff --git a/openmessaging-api/src/test/java/io/openmessaging/internal/AccessPointURITest.java b/openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java similarity index 97% rename from openmessaging-api/src/test/java/io/openmessaging/internal/AccessPointURITest.java rename to openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java index b11ff408..575b21c3 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/AccessPointURITest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java @@ -15,9 +15,9 @@ * limitations under the License. */ -package io.openmessaging.internal; +package io.openmessaging.api.internal; -import io.openmessaging.exception.OMSRuntimeException; +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/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/internal/MessagingAccessPointAdapterTest.java b/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java similarity index 78% rename from openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java rename to openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java index 32dc59a9..11ed3e59 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/internal/MessagingAccessPointAdapterTest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java @@ -15,19 +15,19 @@ * limitations under the License. */ -package io.openmessaging.internal; - -import io.openmessaging.Consumer; -import io.openmessaging.MessagingAccessPoint; -import io.openmessaging.OMS; -import io.openmessaging.OMSBuiltinKeys; -import io.openmessaging.Producer; -import io.openmessaging.PullConsumer; -import io.openmessaging.batch.BatchConsumer; -import io.openmessaging.order.OrderConsumer; -import io.openmessaging.order.OrderProducer; -import io.openmessaging.transaction.LocalTransactionChecker; -import io.openmessaging.transaction.TransactionProducer; +package io.openmessaging.api.internal; + +import io.openmessaging.api.Consumer; +import io.openmessaging.api.MessagingAccessPoint; +import io.openmessaging.api.OMS; +import io.openmessaging.api.OMSBuiltinKeys; +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; @@ -39,15 +39,17 @@ public void getMessagingAccessPoint() { String testURI = "oms:test-vendor://alice@rocketmq.apache.org/us-east:default_space"; Properties properties = new Properties(); - properties.put(OMSBuiltinKeys.DRIVER_IMPL, "io.openmessaging.internal.TestVendor"); + properties.put(OMSBuiltinKeys.DRIVER_IMPL, "io.openmessaging.api.internal.TestVendor"); MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint(testURI, properties); assertThat(messagingAccessPoint).isExactlyInstanceOf(TestVendor.class); } } class TestVendor implements MessagingAccessPoint { - public TestVendor(Properties properties) { + private Properties properties; + public TestVendor(Properties properties) { + this.properties = properties; } @Override public String version() { diff --git a/pom.xml b/pom.xml index fc123e50..8cdf297a 100644 --- a/pom.xml +++ b/pom.xml @@ -122,7 +122,7 @@ UTF-8 en_US - io.openmessaging.internal + io.openmessaging.api.internal From 4227591012692a236ade70c783515eef7b078723 Mon Sep 17 00:00:00 2001 From: duhenglucky Date: Tue, 12 Nov 2019 20:48:40 +0800 Subject: [PATCH 04/23] feat(api) keep forward compatible --- .../io/openmessaging/api/transaction/TransactionStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 70a3d636..e7897542 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java @@ -24,5 +24,5 @@ public enum TransactionStatus { RollbackTransaction, - Unknown + Unknow } From 0faeb0c200710ebbb7278f90ab66a69bc769d7d7 Mon Sep 17 00:00:00 2001 From: duhenglucky Date: Wed, 13 Nov 2019 10:45:26 +0800 Subject: [PATCH 05/23] feat(api) upgrade version to 1.2.0-SNAPSHOT --- openmessaging-admin/pom.xml | 2 +- openmessaging-api-samples/pom.xml | 6 +++--- openmessaging-api/pom.xml | 2 +- .../src/main/java/io/openmessaging/api/ServiceProvider.java | 2 +- .../api/internal/MessagingAccessPointAdapterTest.java | 2 +- pom.xml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index bdd1e69b..d8b7e244 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index c5ee92c0..c0f554ee 100644 --- a/openmessaging-api-samples/pom.xml +++ b/openmessaging-api-samples/pom.xml @@ -2,13 +2,13 @@ io.openmessaging parent - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT 4.0.0 jar openmessaging-api-samples - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT org.slf4j diff --git a/openmessaging-api/pom.xml b/openmessaging-api/pom.xml index d75d12c6..6747eb44 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT 4.0.0 diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java b/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java index da478027..1310a4db 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java @@ -28,7 +28,7 @@ public class ServiceProvider { /** * JDK1.3+ 'Service Provider' specification. */ - public static final String OMS_DRIVER = "META-INF/service/io.openmessaging.api.ONSFactoryAPI"; + public static final String OMS_DRIVER = "META-INF/services/io.openmessaging.api.ONSFactoryAPI"; static { thisClassLoader = getClassLoader(ServiceProvider.class); 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 index 11ed3e59..045d863e 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java @@ -53,7 +53,7 @@ public TestVendor(Properties properties) { } @Override public String version() { - return "1.1.3"; + return "1.2.1"; } @Override public Properties attributes() { diff --git a/pom.xml b/pom.xml index 8cdf297a..99c14df7 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT pom openmessaging From 9ab7f75f3489076c3217c927c407d82eaae28394 Mon Sep 17 00:00:00 2001 From: duhenglucky Date: Wed, 13 Nov 2019 18:57:21 +0800 Subject: [PATCH 06/23] feat(api) polish access point uri --- .../api/internal/AccessPointURI.java | 19 +++++++++++----- .../internal/MessagingAccessPointAdapter.java | 22 +++++-------------- .../api/internal/AccessPointURITest.java | 6 ++--- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java b/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java index be7cbd15..bb8b20b6 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java @@ -22,8 +22,8 @@ import static io.openmessaging.api.OMSResponseStatus.generateException; /** - * Represents a AccessPoint String. - * The Connection String describes the details to connect a specific OMS service provider. + * 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:"; @@ -41,9 +41,10 @@ public class AccessPointURI { *

    * * More details please refer to: - * Access Point Schema + * Access Point + * Schema */ - private static final String PATTERN = "^oms:.+://.+/.+$"; + private static final String PATTERN = "^oms:.+://.+(/.+)?"; AccessPointURI(String accessPointString) { validateAccessPointString(accessPointString); @@ -58,9 +59,15 @@ public class AccessPointURI { unprocessedString = unprocessedString.substring(driverType.length() + 3); idx = unprocessedString.lastIndexOf('/'); + String userAndHostInformation; - this.region = unprocessedString.substring(idx + 1); - String userAndHostInformation = unprocessedString.substring(0, idx); + if (idx != -1) { + this.region = unprocessedString.substring(idx + 1); + userAndHostInformation = unprocessedString.substring(0, idx); + } else { + this.region = null; + userAndHostInformation = unprocessedString; + } idx = userAndHostInformation.indexOf('@'); diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java index af2f1834..fe951eb6 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java @@ -18,7 +18,6 @@ package io.openmessaging.api.internal; import io.openmessaging.api.MessagingAccessPoint; -import io.openmessaging.api.OMS; import io.openmessaging.api.OMSBuiltinKeys; import io.openmessaging.api.OMSResponseStatus; import io.openmessaging.api.exception.OMSRuntimeException; @@ -49,14 +48,17 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url, Propertie 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()); + if (accessPointURI.getRegion() != null) { + attributes.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion()); + } + if (accessPointURI.getAccountId() != null) { + attributes.put(OMSBuiltinKeys.ACCOUNT_ID, accessPointURI.getAccountId()); + } try { Class driverImplClass = Class.forName(driverImpl); 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); @@ -70,16 +72,4 @@ private static String parseDriverImpl(String driverType, Properties attributes) 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/test/java/io/openmessaging/api/internal/AccessPointURITest.java b/openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java index 575b21c3..4ee08409 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java @@ -37,12 +37,12 @@ public void testParse_DriverIsIllegal() { } - String missRegion = "oms:rocketmq://alice@rocketmq.apache.org/"; + String missHost = "oms:rocketmq://"; try { - new AccessPointURI(missRegion); + new AccessPointURI(missHost); failBecauseExceptionWasNotThrown(OMSRuntimeException.class); } catch (Exception e) { - assertThat(e).hasMessageContaining(String.format("The OMS driver URL [%s] is illegal.", missRegion)); + assertThat(e).hasMessageContaining(String.format("The OMS driver URL [%s] is illegal.", missHost)); } } From 4503e1d8e4dd6badffd5c9c94cf41dab6bd21a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Mon, 18 Nov 2019 11:19:42 +0800 Subject: [PATCH 07/23] feat(api) remove some customize config --- .../java/io/openmessaging/api/LifeCycle.java | 1 + .../java/io/openmessaging/api/ONSFactory.java | 197 ------------------ .../io/openmessaging/api/ONSFactoryAPI.java | 33 --- .../openmessaging/api/PropertyKeyConst.java | 74 ------- .../openmessaging/api/PropertyValueConst.java | 27 --- 5 files changed, 1 insertion(+), 331 deletions(-) delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/ONSFactory.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/PropertyValueConst.java diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java index 8a1ffe54..ff660a7c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java @@ -15,6 +15,7 @@ * limitations under the License. */ package io.openmessaging.api; + public interface LifeCycle { boolean isStarted(); diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactory.java b/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactory.java deleted file mode 100644 index 65339711..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactory.java +++ /dev/null @@ -1,197 +0,0 @@ -package io.openmessaging.api; - -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; - -/** - * {@link OMS} is recommended. - */ -@Deprecated -public class ONSFactory { - - private static ONSFactoryAPI onsFactory; - - static { - onsFactory = (ONSFactoryAPI) ServiceProvider.load(ServiceProvider.OMS_DRIVER, ONSFactoryAPI.class).get(0); - } - - /** - * Create Producer - * - *

    - * properties - * Require: - *

      - *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. - *
    3. {@link PropertyKeyConst#AccessKey}
    4. - *
    5. {@link PropertyKeyConst#SecretKey}
    6. - *
    7. {@link PropertyKeyConst#ONSAddr}
    8. - *
    - * Optional: - *
      - *
    1. {@link PropertyKeyConst#OnsChannel}
    2. - *
    3. {@link PropertyKeyConst#SendMsgTimeoutMillis}
    4. - *
    5. {@link PropertyKeyConst#NAMESRV_ADDR} will override {@link PropertyKeyConst#ONSAddr}
    6. - *
    - *

    - * - * - *

    - * sample: - *

    -     *        Properties props = ...;
    -     *        Producer producer = ONSFactory.createProducer(props);
    -     *        producer.start();
    -     *
    -     *
    -     *        Message msg = ...;
    -     *        SendResult result = producer.send(msg);
    -     *
    -     *        producer.shutdown();
    -     *   
    - *

    - * - * @param properties Producer's configuration - * @return {@link Producer} Thread safe {@link Producer} instance - */ - public static Producer createProducer(final Properties properties) { - return onsFactory.createProducer(properties); - } - - /** - * Create OrderProducer - *

    - * properties - * Require: - *

      - *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. - *
    3. {@link PropertyKeyConst#AccessKey}
    4. - *
    5. {@link PropertyKeyConst#SecretKey}
    6. - *
    7. {@link PropertyKeyConst#ONSAddr}
    8. - *
    - * Optional: - *
      - *
    • {@link PropertyKeyConst#NAMESRV_ADDR}
    • - *
    • {@link PropertyKeyConst#OnsChannel}
    • - *
    • {@link PropertyKeyConst#SendMsgTimeoutMillis}
    • - *
    - *

    - * - * @param properties Producer configuration - * @return {@code OrderProducer} Thread safe {@link OrderProducer} instance - */ - public static OrderProducer createOrderProducer(final Properties properties) { - return onsFactory.createOrderProducer(properties); - } - - /** - * Create Transaction Producer - *

    - * propertiesRequires: - *

      - *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. - *
    3. {@link PropertyKeyConst#AccessKey}
    4. - *
    5. {@link PropertyKeyConst#SecretKey}
    6. - *
    7. {@link PropertyKeyConst#ONSAddr}
    8. - *
    - * Optional: - *
      - *
    • {@link PropertyKeyConst#NAMESRV_ADDR}
    • - *
    • {@link PropertyKeyConst#OnsChannel}
    • - *
    • {@link PropertyKeyConst#SendMsgTimeoutMillis}
    • - *
    • {@link PropertyKeyConst#CheckImmunityTimeInSeconds}
    • - *
    - *

    - * - * @param properties Producer configuration - * @return {@code TransactionProducer} Thread safe {@link TransactionProducer} instance - */ - public static TransactionProducer createTransactionProducer(final Properties properties, - final LocalTransactionChecker checker) { - return onsFactory.createTransactionProducer(properties, checker); - } - - /** - * Create Consumer - *

    - * properties - * Requires: - *

      - *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. - *
    3. {@link PropertyKeyConst#AccessKey}
    4. - *
    5. {@link PropertyKeyConst#SecretKey}
    6. - *
    7. {@link PropertyKeyConst#ONSAddr}
    8. - *
    - * Optional: - *
      - *
    • {@link PropertyKeyConst#ConsumeThreadNums}
    • - *
    • {@link PropertyKeyConst#ConsumeTimeout}
    • - *
    • {@link PropertyKeyConst#OnsChannel}
    • - *
    - *

    - * - * @param properties Consumer's configuration - * @return {@code Consumer} Thread safe {@link Consumer} instance - */ - public static Consumer createConsumer(final Properties properties) { - return onsFactory.createConsumer(properties); - } - - /** - * Create BatchConsumer - *

    - * properties - * Requires: - *

      - *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. - *
    3. {@link PropertyKeyConst#AccessKey}
    4. - *
    5. {@link PropertyKeyConst#SecretKey}
    6. - *
    7. {@link PropertyKeyConst#ONSAddr}
    8. - *
    - * Optional: - *
      - *
    • {@link PropertyKeyConst#ConsumeThreadNums}
    • - *
    • {@link PropertyKeyConst#ConsumeTimeout}
    • - *
    • {@link PropertyKeyConst#ConsumeMessageBatchMaxSize}
    • - *
    • {@link PropertyKeyConst#OnsChannel}
    • - *
    - *

    - * - * @param properties BatchConsumer's configuration - * @return {@code BatchConsumer} Thread safe {@link BatchConsumer} instance - */ - public static BatchConsumer createBatchConsumer(final Properties properties) { - return onsFactory.createBatchConsumer(properties); - } - - /** - * Create Order Consumer - *

    - * properties - * Requires: - *

      - *
    1. {@link PropertyKeyConst#GROUP_ID}
    2. - *
    3. {@link PropertyKeyConst#AccessKey}
    4. - *
    5. {@link PropertyKeyConst#SecretKey}
    6. - *
    7. {@link PropertyKeyConst#ONSAddr}
    8. - *
    - * Optional: - *
      - *
    • {@link PropertyKeyConst#ConsumeThreadNums}
    • - *
    • {@link PropertyKeyConst#ConsumeTimeout}
    • - *
    • {@link PropertyKeyConst#OnsChannel}
    • - *
    - *

    - * - * @param properties Consumer's configuration - * @return {@code OrderConsumer} Thread safe {@link OrderConsumer} instance - */ - public static OrderConsumer createOrderedConsumer(final Properties properties) { - return onsFactory.createOrderedConsumer(properties); - } - -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java b/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java deleted file mode 100644 index f249dc55..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/ONSFactoryAPI.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.openmessaging.api; - -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; - -/** - * {@link MessagingAccessPoint} is recommended. - */ -@Deprecated -public interface ONSFactoryAPI { - - Producer createProducer(final Properties properties); - - - Consumer createConsumer(final Properties properties); - - - BatchConsumer createBatchConsumer(final Properties properties); - - - OrderProducer createOrderProducer(final Properties properties); - - - OrderConsumer createOrderedConsumer(final Properties properties); - - - TransactionProducer createTransactionProducer(final Properties properties, - final LocalTransactionChecker checker); -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java b/openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java deleted file mode 100644 index 58e616b6..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/PropertyKeyConst.java +++ /dev/null @@ -1,74 +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.api; - -public class PropertyKeyConst implements OMSBuiltinKeys { - - public static final String MessageModel = "MessageModel"; - - public static final String GROUP_ID = "GROUP_ID"; - - public static final String AccessKey = "AccessKey"; - - public static final String SecretKey = "SecretKey"; - - public static final String SecurityToken = "SecurityToken"; - - public static final String SendMsgTimeoutMillis = "SendMsgTimeoutMillis"; - - @Deprecated - public static final String ONSAddr = "ONSAddr"; - - @Deprecated - public static final String NAMESRV_ADDR = "NAMESRV_ADDR"; - - public static final String ConsumeThreadNums = "ConsumeThreadNums"; - - public static final String OnsChannel = "OnsChannel"; - - public static final String MQType = "MQType"; - - public static final String isVipChannelEnabled = "isVipChannelEnabled"; - - public static final String SuspendTimeMillis = "suspendTimeMillis"; - - public static final String MaxReconsumeTimes = "maxReconsumeTimes"; - - public static final String ConsumeTimeout = "consumeTimeout"; - - public static final String CheckImmunityTimeInSeconds = "CheckImmunityTimeInSeconds"; - - public static final String PostSubscriptionWhenPull = "PostSubscriptionWhenPull"; - - public static final String ConsumeMessageBatchMaxSize = "ConsumeMessageBatchMaxSize"; - - public static final String MaxCachedMessageAmount = "maxCachedMessageAmount"; - - public static final String MaxCachedMessageSizeInMiB = "maxCachedMessageSizeInMiB"; - - public static final String InstanceName = "InstanceName"; - - @Deprecated - public static final String EXACTLYONCE_DELIVERY = "exactlyOnceDelivery"; - - public static final String QOS = "qos"; - - public static final String EXACTLYONCE_RM_REFRESHINTERVAL = "exactlyOnceRmRefreshInterval"; - - public static final String MAX_BATCH_MESSAGE_COUNT = "maxBatchMessageCount"; - -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/PropertyValueConst.java b/openmessaging-api/src/main/java/io/openmessaging/api/PropertyValueConst.java deleted file mode 100644 index 1a990808..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/PropertyValueConst.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.api; - - -public class PropertyValueConst { - - - public static final String BROADCASTING = "BROADCASTING"; - - - public static final String CLUSTERING = "CLUSTERING"; -} From 0496a351b6296d59dbf383c8df7ffcd9a1954876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Tue, 19 Nov 2019 14:25:28 +0800 Subject: [PATCH 08/23] doc(api) add comment and version for APIs --- .../java/io/openmessaging/api/Constants.java | 21 --- .../java/io/openmessaging/api/Consumer.java | 30 ++++ .../io/openmessaging/api/Credentials.java | 12 ++ .../io/openmessaging/api/ExpressionType.java | 6 + .../java/io/openmessaging/api/LifeCycle.java | 30 ++++ .../java/io/openmessaging/api/Message.java | 63 ++++---- .../io/openmessaging/api/MessageAccessor.java | 34 ++++- .../io/openmessaging/api/MessageListener.java | 22 ++- .../io/openmessaging/api/OMSBuiltinKeys.java | 14 +- .../openmessaging/api/OnExceptionContext.java | 19 ++- .../java/io/openmessaging/api/Producer.java | 58 ++++++- .../io/openmessaging/api/SendCallback.java | 18 +++ .../java/io/openmessaging/api/SendResult.java | 8 +- .../io/openmessaging/api/ServiceProvider.java | 144 ------------------ .../io/openmessaging/api/TopicPartition.java | 5 + .../api/batch/BatchConsumer.java | 20 +++ .../api/batch/BatchMessageListener.java | 15 +- .../openmessaging/api/bean/Subscription.java | 4 + .../api/bean/SubscriptionExt.java | 5 +- .../internal/MessagingAccessPointAdapter.java | 2 +- .../api/order/MessageOrderListener.java | 15 ++ .../api/order/MessageQueueSelector.java | 25 --- .../openmessaging/api/order/OrderAction.java | 13 +- .../api/order/OrderConsumer.java | 27 ++++ .../api/order/OrderProducer.java | 14 ++ .../transaction/LocalTransactionChecker.java | 16 +- .../transaction/LocalTransactionExecutor.java | 14 ++ .../api/transaction/TransactionProducer.java | 20 +++ .../api/transaction/TransactionStatus.java | 7 +- 29 files changed, 439 insertions(+), 242 deletions(-) delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/Constants.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/order/MessageQueueSelector.java diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Constants.java b/openmessaging-api/src/main/java/io/openmessaging/api/Constants.java deleted file mode 100644 index e436c455..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Constants.java +++ /dev/null @@ -1,21 +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.api; - -public class Constants { - public static final String TRANSACTION_ID = "__transactionId__"; -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java index 9e6c901e..bb1c0948 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java @@ -16,11 +16,41 @@ */ package io.openmessaging.api; +/** + * Consumer interface. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public interface Consumer extends LifeCycle, Credentials { + /** + * 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 index 41eca294..674b9db5 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Credentials.java @@ -15,8 +15,20 @@ * 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 index 4bb3712d..64a444a3 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/ExpressionType.java @@ -16,6 +16,12 @@ */ package io.openmessaging.api; +/** + * Message filter expression type. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public enum ExpressionType { SQL92, diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java index ff660a7c..8b562d8f 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/LifeCycle.java @@ -16,12 +16,42 @@ */ package io.openmessaging.api; +/** + * 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.2.0 + * @since OMS 1.2.0 + */ 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. + */ void start(); + /** + * 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 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 index eb39c33c..23ac4175 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Message.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Message.java @@ -19,28 +19,57 @@ 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; @@ -49,7 +78,6 @@ public Message(String topic, String tag, String key, byte[] body) { this.putSystemProperties(SystemPropKey.KEY, key); } - public void putSystemProperties(final String key, final String value) { if (null == this.systemProperties) { this.systemProperties = new Properties(); @@ -60,12 +88,10 @@ public void putSystemProperties(final String key, final String 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(); @@ -76,7 +102,6 @@ public void putUserProperties(final String key, final String value) { } } - public String getUserProperties(final String key) { if (null != this.userProperties) { return (String) this.userProperties.get(key); @@ -85,22 +110,18 @@ public String getUserProperties(final String 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); @@ -109,27 +130,22 @@ public String getSystemProperties(final String 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); } @@ -164,7 +180,6 @@ public void setBody(byte[] body) { this.body = body; } - public int getReconsumeTimes() { String pro = this.getSystemProperties(SystemPropKey.RECONSUMETIMES); if (pro != null) { @@ -174,12 +189,10 @@ public int getReconsumeTimes() { 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) { @@ -189,23 +202,19 @@ public long getBornTimestamp() { 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) { @@ -224,7 +233,6 @@ public void setShardingKey(final String value) { putSystemProperties(SystemPropKey.SHARDINGKEY, value); } - public void setStartDeliverTime(final long value) { putSystemProperties(SystemPropKey.STARTDELIVERTIME, String.valueOf(value)); } @@ -235,7 +243,6 @@ public String toString() { + (body != null ? body.length : 0) + "]"; } - static public class SystemPropKey { public static final String TAG = "__TAG"; public static final String KEY = "__KEY"; diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java index ff8fbdfa..a20e72b0 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageAccessor.java @@ -18,22 +18,50 @@ 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 index db6fdd40..4cc2b379 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessageListener.java @@ -16,8 +16,28 @@ */ 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/OMSBuiltinKeys.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java index de20eea5..30bd27df 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java @@ -38,17 +38,23 @@ public interface OMSBuiltinKeys { String ACCESS_POINTS = "ACCESS_POINTS"; /** - * The {@code ACCOUNT_ID} key shows the specified account info in OMS driver schema. + * The {@code ACCESS_KEY} key shows the specified access key in OMS driver schema. */ - String ACCOUNT_ID = "ACCOUNT_ID"; + String ACCESS_KEY = "AccessKey"; /** - * The {@code ACCOUNT_KEY} key shows the specified account key in OMS attribute. + * The {@code SECRET_KEY} key shows the specified secret key in OMS attribute. */ - String ACCOUNT_KEY = "ACCOUNT_KEY"; + String SECRET_KEY = "SecretKey"; + + /** + * The {@code SECURITY_TOKEN} key shows the specified security token in OMS attribute. + */ + String SECURITY_TOKEN = "SecurityToken"; /** * The {@code REGION} key shows the specified region in OMS driver schema. */ String REGION = "REGION"; + } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java index 49b5800d..ab99c254 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java @@ -18,13 +18,22 @@ 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; - private OMSRuntimeException exception; + /** + * Detailed exception stack information. + */ + private OMSRuntimeException omsRuntimeException; public String getMessageId() { return messageId; @@ -42,11 +51,11 @@ public void setTopic(String topic) { this.topic = topic; } - public OMSRuntimeException getException() { - return exception; + public OMSRuntimeException getOmsRuntimeException() { + return omsRuntimeException; } - public void setException(OMSRuntimeException exception) { - this.exception = exception; + public void setOmsRuntimeException(OMSRuntimeException omsRuntimeException) { + this.omsRuntimeException = omsRuntimeException; } } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java index 5e7fdcee..ba4e46fe 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java @@ -16,17 +16,71 @@ */ 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 LifeCycle, Credentials { + /** + * 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); - - SendResult send(final Message message, final String shardingKey); } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java b/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java index 168abf0d..e9c0b2c1 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/SendCallback.java @@ -16,9 +16,27 @@ */ package io.openmessaging.api; +/** + * Call back interface used in {@link Producer#sendAsync(Message, SendCallback)}. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public interface SendCallback { + /** + * When message send success, this method will be invoked. + * + * @param sendResult send message result. + * @see SendResult + */ void onSuccess(final SendResult sendResult); + /** + * When message send failed, this method will be invoked. + * + * @param context send message exception context. + * @see OnExceptionContext + */ 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 index 94458334..e8a030c6 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/SendResult.java @@ -16,18 +16,22 @@ */ 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; } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java b/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java deleted file mode 100644 index 1310a4db..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/ServiceProvider.java +++ /dev/null @@ -1,144 +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.api; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -public class ServiceProvider { - - /** - * A reference to the classloader that loaded this class. It's more efficient to compute it once and cache it here. - */ - private static ClassLoader thisClassLoader; - - /** - * JDK1.3+ 'Service Provider' specification. - */ - public static final String OMS_DRIVER = "META-INF/services/io.openmessaging.api.ONSFactoryAPI"; - - static { - thisClassLoader = getClassLoader(ServiceProvider.class); - } - - /** - * Returns a string that uniquely identifies the specified object, including its class. - *

    - * The returned string is of form "classname@hashcode", ie is the same as the return value of the Object.toString() method, but works even when the specified object's class has overidden the toString method. - * - * @param o may be null. - * @return a string of form classname@hashcode, or "null" if param o is null. - */ - protected static String objectId(Object o) { - if (o == null) { - return "null"; - } else { - return o.getClass().getName() + "@" + System.identityHashCode(o); - } - } - - protected static ClassLoader getClassLoader(Class clazz) { - try { - return clazz.getClassLoader(); - } catch (SecurityException e) { - throw e; - } - } - - protected static ClassLoader getContextClassLoader() { - ClassLoader classLoader = null; - try { - classLoader = Thread.currentThread().getContextClassLoader(); - } catch (SecurityException ex) { - /** - * The getContextClassLoader() method throws SecurityException when the context - * class loader isn't an ancestor of the calling class's class - * loader, or if security permissions are restricted. - */ - } - return classLoader; - } - - protected static InputStream getResourceAsStream(ClassLoader loader, String name) { - if (loader != null) { - return loader.getResourceAsStream(name); - } else { - return ClassLoader.getSystemResourceAsStream(name); - } - } - - public static List load(String name, Class clazz) { - List services = new ArrayList(); - try { - ArrayList names = new ArrayList(); - final InputStream is = getResourceAsStream(getContextClassLoader(), name); - if (is != null) { - BufferedReader reader; - try { - reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); - } catch (java.io.UnsupportedEncodingException e) { - reader = new BufferedReader(new InputStreamReader(is)); - } - String serviceName = reader.readLine(); - while (serviceName != null && !"".equals(serviceName)) { - if (!names.contains(serviceName)) { - names.add(serviceName); - } - - services.add((T) initService(getContextClassLoader(), serviceName, clazz)); - - serviceName = reader.readLine(); - } - reader.close(); - } else { - // is == null - } - } catch (Exception e) { - } - return services; - } - - protected static T initService(ClassLoader classLoader, String serviceName, Class clazz) { - Class serviceClazz = null; - try { - if (classLoader != null) { - try { - // Warning: must typecast here & allow exception to be generated/caught & recast properly - serviceClazz = classLoader.loadClass(serviceName); - if (clazz.isAssignableFrom(serviceClazz)) { - - } else { - - } - return (T) serviceClazz.newInstance(); - } catch (ClassNotFoundException ex) { - if (classLoader == thisClassLoader) { - // Nothing more to try, onwards. - throw ex; - } - // Ignore exception, continue - } catch (NoClassDefFoundError e) { - if (classLoader == thisClassLoader) { - throw e; - } - // Ignore exception, continue - } - } - } catch (Exception e) { - } - return (T) serviceClazz; - } -} diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java index 34c226e6..e8add333 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java @@ -16,6 +16,11 @@ */ package io.openmessaging.api; +/** + * Used for describe a topic and + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public class TopicPartition { private String topic; 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 index baeef0f4..da122ed9 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java @@ -20,9 +20,29 @@ import io.openmessaging.api.Credentials; import io.openmessaging.api.LifeCycle; +/** + * Batch message consumer, used to subscribe to messages in batch. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public interface BatchConsumer extends LifeCycle, Credentials { + /** + * 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 index 3a0e44ca..45e62cae 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchMessageListener.java @@ -22,8 +22,21 @@ 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 index 7253342e..4b0787d2 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/bean/Subscription.java @@ -19,6 +19,10 @@ import io.openmessaging.api.ExpressionType; +/** + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public class Subscription { private String topic; private String expression; 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 index 2fb52769..e50b1a47 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/bean/SubscriptionExt.java @@ -17,7 +17,10 @@ package io.openmessaging.api.bean; - +/** + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public class SubscriptionExt extends Subscription { private boolean persistence = true; diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java index fe951eb6..6555fc79 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java @@ -52,7 +52,7 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url, Propertie attributes.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion()); } if (accessPointURI.getAccountId() != null) { - attributes.put(OMSBuiltinKeys.ACCOUNT_ID, accessPointURI.getAccountId()); + attributes.put(OMSBuiltinKeys.ACCESS_KEY, accessPointURI.getAccountId()); } try { 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 index 0896ba50..9f93293c 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageOrderListener.java @@ -19,7 +19,22 @@ 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/MessageQueueSelector.java b/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageQueueSelector.java deleted file mode 100644 index df57586c..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/order/MessageQueueSelector.java +++ /dev/null @@ -1,25 +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.api.order; - -import io.openmessaging.api.Message; - -public interface MessageQueueSelector { - - int select(final int queueTotal, final Message msg, final Object arg); -} 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 index 075c7c0e..7edafc4d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderAction.java @@ -17,10 +17,21 @@ 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 index 70c5afee..0bd900e7 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java @@ -18,12 +18,39 @@ package io.openmessaging.api.order; import io.openmessaging.api.Credentials; +import io.openmessaging.api.ExpressionType; import io.openmessaging.api.LifeCycle; 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 LifeCycle, Credentials { + /** + * 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 index e74302f0..f7d00e26 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java @@ -22,7 +22,21 @@ 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 LifeCycle, Credentials { + /** + * 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 index d69d548d..9ab212b0 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java @@ -18,9 +18,21 @@ import io.openmessaging.api.Message; +/** + * Check local transactions, callback debugger 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/LocalTransactionExecutor.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java index 0da501fb..ddce79fc 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java @@ -19,7 +19,21 @@ import io.openmessaging.api.Message; +/** + * Local transaction executor + * + * @version OMS 1.2.0 + * @since OMS 1.2.0  + */ public interface LocalTransactionExecutor { + /** + * 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 index 2f1b0d2c..55ae24f1 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java @@ -22,8 +22,28 @@ 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 LifeCycle, Credentials { + /** + * 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 LocalTransactionExecutor 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 index e7897542..dba0d3d3 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionStatus.java @@ -17,7 +17,12 @@ package io.openmessaging.api.transaction; - +/** + * Transaction status. + * + * @version OMS 1.2.0 + * @since OMS 1.2.0 + */ public enum TransactionStatus { CommitTransaction, From 54dbb99bd16502b8ef8dac1c761e8151ae68fd1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Tue, 19 Nov 2019 15:34:11 +0800 Subject: [PATCH 09/23] feat(api) A little change for forward compatibility --- .../api/transaction/LocalTransactionChecker.java | 2 +- ...TransactionExecutor.java => LocalTransactionExecuter.java} | 4 ++-- .../io/openmessaging/api/transaction/TransactionProducer.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename openmessaging-api/src/main/java/io/openmessaging/api/transaction/{LocalTransactionExecutor.java => LocalTransactionExecuter.java} (94%) 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 index 9ab212b0..4cd3eaa8 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionChecker.java @@ -19,7 +19,7 @@ import io.openmessaging.api.Message; /** - * Check local transactions, callback debugger by Broker. + * Check local transactions, callback by broker. * * @version OMS 1.2.0 * @since OMS 1.2.0 diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecuter.java similarity index 94% rename from openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java rename to openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecuter.java index ddce79fc..2ed9cd5d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecutor.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/LocalTransactionExecuter.java @@ -20,12 +20,12 @@ import io.openmessaging.api.Message; /** - * Local transaction executor + * Local transaction executor. * * @version OMS 1.2.0 * @since OMS 1.2.0  */ -public interface LocalTransactionExecutor { +public interface LocalTransactionExecuter { /** * Execute local transactions, rewritten by the application. 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 index 55ae24f1..7e29a01e 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java @@ -45,6 +45,6 @@ public interface TransactionProducer extends LifeCycle, Credentials { * @return Send result */ SendResult send(final Message message, - final LocalTransactionExecutor localTransactionExecutor, + final LocalTransactionExecuter localTransactionExecutor, final Object arg); } From c1fbb643063e0fc65051242090555d44731e1689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Tue, 19 Nov 2019 19:37:20 +0800 Subject: [PATCH 10/23] feat(api) A little change for forward compatibility --- .../samples/producer/TransactionProducerApp.java | 4 ++-- .../java/io/openmessaging/api/OnExceptionContext.java | 11 ++++++----- .../api/exception/OMSRuntimeException.java | 10 +++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) 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 d492946d..31efdbba 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 @@ -22,7 +22,7 @@ import io.openmessaging.api.OMS; import io.openmessaging.api.SendResult; import io.openmessaging.api.transaction.LocalTransactionChecker; -import io.openmessaging.api.transaction.LocalTransactionExecutor; +import io.openmessaging.api.transaction.LocalTransactionExecuter; import io.openmessaging.api.transaction.TransactionProducer; import io.openmessaging.api.transaction.TransactionStatus; import java.util.Properties; @@ -51,7 +51,7 @@ public void run() { Message message = new Message("NS://Topic", "TagA", "Hello MQ".getBytes()); //Sends a transaction message to the specified destination synchronously. - SendResult result = producer.send(message, new LocalTransactionExecutor() { + SendResult result = producer.send(message, new LocalTransactionExecuter() { @Override public TransactionStatus execute(Message message, Object arg) { return TransactionStatus.CommitTransaction; } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java index ab99c254..3d3b782f 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java @@ -33,7 +33,7 @@ public class OnExceptionContext { /** * Detailed exception stack information. */ - private OMSRuntimeException omsRuntimeException; + private OMSRuntimeException exception; public String getMessageId() { return messageId; @@ -51,11 +51,12 @@ public void setTopic(String topic) { this.topic = topic; } - public OMSRuntimeException getOmsRuntimeException() { - return omsRuntimeException; + + public OMSRuntimeException getException() { + return exception; } - public void setOmsRuntimeException(OMSRuntimeException omsRuntimeException) { - this.omsRuntimeException = omsRuntimeException; + public void setException(OMSRuntimeException exception) { + this.exception = exception; } } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSRuntimeException.java b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSRuntimeException.java index 46cefb05..2445668d 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSRuntimeException.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/exception/OMSRuntimeException.java @@ -38,13 +38,21 @@ public class OMSRuntimeException extends RuntimeException { * * @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(); From 5467bb21ea8e522fee862f59de3fe059e67ee12e Mon Sep 17 00:00:00 2001 From: vongosling Date: Fri, 22 Nov 2019 11:11:21 +0800 Subject: [PATCH 11/23] fix(travis): build pass, adding openjdk11 matrix verification --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7047779b..da5947a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +dist: trusty + language: java addons: @@ -17,8 +19,10 @@ install: jdk: - oraclejdk8 - oraclejdk9 +- oraclejdk11 - openjdk7 -- openjdk6 +- openjdk8 + script: mvn install env: From 392984b1684750da18324873a1c82ec8e33cdf04 Mon Sep 17 00:00:00 2001 From: vongosling Date: Fri, 22 Nov 2019 11:14:24 +0800 Subject: [PATCH 12/23] Remove it --- openmessaging-api/README.md | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 openmessaging-api/README.md 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 From e440ba6d7912c2121c7606eeb92023458f36488e Mon Sep 17 00:00:00 2001 From: vongosling Date: Fri, 22 Nov 2019 11:23:55 +0800 Subject: [PATCH 13/23] fix(conflict): fix the conflict between maven compiler level 1.8 and travis openjdk7 --- .travis.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index da5947a6..76da1a34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,6 @@ dist: trusty language: java - -addons: - apt: - packages: - - openjdk-6-jdk install: - echo "Downloading Maven 3.0"; @@ -20,11 +15,10 @@ jdk: - oraclejdk8 - oraclejdk9 - oraclejdk11 -- openjdk7 - 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= From 4475cbbf45b1787df7a5a1f6546f4608bd569fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Fri, 22 Nov 2019 14:38:29 +0800 Subject: [PATCH 14/23] feat(pullconsumer) change the jdk version requirment from 1.8 to 1.7 --- .../samples/consumer/PullConsumerApp.java | 3 +-- .../io/openmessaging/api/OnExceptionContext.java | 1 + .../java/io/openmessaging/api/PullConsumer.java | 15 +++++++-------- pom.xml | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) 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 8d8c3c2a..e08b1856 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 @@ -22,7 +22,6 @@ import io.openmessaging.api.OMS; import io.openmessaging.api.PullConsumer; import io.openmessaging.api.TopicPartition; -import java.time.Duration; import java.util.List; import java.util.Properties; import java.util.Set; @@ -48,7 +47,7 @@ public void run() { consumer.assign(topicPartitions); consumer.start(); - List message = consumer.poll(Duration.ofMillis(1000)); + List message = consumer.poll(1000); System.out.println("Received message: " + message); //Acknowledge the consumed message consumer.commitSync(); diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java index 3d3b782f..44dbd57f 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OnExceptionContext.java @@ -35,6 +35,7 @@ public class OnExceptionContext { */ private OMSRuntimeException exception; + public String getMessageId() { return messageId; } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java index ff809d92..15dbc9ad 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java @@ -16,7 +16,6 @@ */ package io.openmessaging.api; -import java.time.Duration; import java.util.Collection; import java.util.List; import java.util.Set; @@ -65,13 +64,13 @@ interface TopicPartitionChangeListener { * 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 + * @param timeout in millisecond * @return */ - List poll(Duration timeout); + List poll(long timeout); /** - * Overrides the fetch offsets that the consumer will use on the next {@link #poll(Duration)} }. If this API is invoked + * 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. * @@ -82,7 +81,7 @@ interface TopicPartitionChangeListener { /** * Overrides the fetch offsets with the beginning offset in server that the consumer will use on the next {@link - * #poll(Duration)} }. + * #poll(long)} }. * * @param topicPartition */ @@ -90,14 +89,14 @@ interface TopicPartitionChangeListener { /** * Overrides the fetch offsets with the end offset in server that the consumer will use on the next {@link - * #poll(Duration)} }. + * #poll(long)} }. * * @param topicPartition */ void seekToEnd(TopicPartition topicPartition); /** - * Suspend fetching from the requested message queues. Future calls to {@link #poll(Duration)} will not return any + * 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 @@ -109,7 +108,7 @@ interface TopicPartitionChangeListener { /** * Resume specified message queues which have been paused with {@link #pause(Collection)}. New calls to {@link - * #poll(Duration)} will return records from these partitions if there are any to be fetched. If the message queues were + * #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 diff --git a/pom.xml b/pom.xml index 99c14df7..29db3d49 100644 --- a/pom.xml +++ b/pom.xml @@ -51,8 +51,8 @@ UTF-8 - 1.8 - 1.8 + 1.7 + 1.7 From 88cc2d35052ee2925224fc32c725ca87c968940c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Wed, 25 Dec 2019 20:14:17 +0800 Subject: [PATCH 15/23] feat(OMS) polish MessagingAccessPoint builder --- .../samples/consumer/PullConsumerApp.java | 7 +- .../samples/consumer/PushConsumerApp.java | 7 +- .../samples/producer/ProducerApp.java | 7 +- .../producer/TransactionProducerApp.java | 7 +- .../api/MessagingAccessPoint.java | 3 +- .../main/java/io/openmessaging/api/OMS.java | 128 ++++++++++++++---- .../io/openmessaging/api/OMSBuiltinKeys.java | 29 ++-- .../io/openmessaging/api/TopicPartition.java | 9 +- .../api/internal/AccessPointURI.java | 108 --------------- .../internal/MessagingAccessPointAdapter.java | 15 +- .../api/internal/AccessPointURITest.java | 83 ------------ .../MessagingAccessPointAdapterTest.java | 13 +- 12 files changed, 162 insertions(+), 254 deletions(-) delete mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java delete mode 100644 openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java 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 e08b1856..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 @@ -30,7 +30,12 @@ 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(properties); 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 f370a8cf..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 @@ -30,7 +30,12 @@ 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:9876"); + OMS.builder() + .region("Shenzhen") + .endpoint("127.0.0.1:9876") + .driver("rocketmq") + .withCredentials(new Properties()) + .build(); Properties properties = new Properties(); final Consumer consumer = messagingAccessPoint.createConsumer(properties); 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 bcde63f1..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 @@ -29,7 +29,12 @@ public class ProducerApp { public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = - OMS.getMessagingAccessPoint("oms:rocketmq://alice@rocketmq.apache.org"); + OMS.builder() + .region("shanghai,shenzhen") + .endpoint("127.0.0.1:9876") + .driver("rocketmq") + .withCredentials(new Properties()) + .build(); final Producer producer = messagingAccessPoint.createProducer(new Properties()); producer.start(); 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 31efdbba..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 @@ -30,7 +30,12 @@ public class TransactionProducerApp { public static void main(String[] args) { final MessagingAccessPoint messagingAccessPoint = - OMS.getMessagingAccessPoint("oms:rocketmq://alice@rocketmq.apache.org/us-east"); + 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 diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java b/openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java index 4c297847..5166d79e 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/MessagingAccessPoint.java @@ -54,11 +54,10 @@ 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 diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java index 5d387fce..4ca3a212 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java @@ -17,57 +17,133 @@ package io.openmessaging.api; -import io.openmessaging.api.exception.OMSRuntimeException; 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 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 an 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.1.0 - * @since OMS 1.1.0 + * @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(); + } + /** - * Returns a {@code MessagingAccessPoint} instance from the specified OMS driver url. + * Set the endpoint provided by messaging vendor. * - * @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. + * @param endpoint + * @return */ - public static MessagingAccessPoint getMessagingAccessPoint(String url) { - return getMessagingAccessPoint(url, new Properties()); + public OMS endpoint(String endpoint) { + this.properties.put(OMSBuiltinKeys.ENDPOINT, endpoint); + return this; } /** - * 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. + * Set the region provided by messaging vendor. * - * There are some standard attributes defined by OMS for this method, the same as {@link - * MessagingAccessPoint#attributes()} ()} + * @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 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. + * @param driver + * @return */ - public static MessagingAccessPoint getMessagingAccessPoint(String url, Properties attributes) { - return MessagingAccessPointAdapter.getMessagingAccessPoint(url, attributes); + 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 this.build(properties); + } /** * The version format is X.Y.Z (Major.Minor.Patch), a pre-release version may be denoted by appending a hyphen and a diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java index 30bd27df..5fbf3809 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMSBuiltinKeys.java @@ -27,34 +27,37 @@ public interface OMSBuiltinKeys { /** * The {@code DRIVER_IMPL} key represents the vendor implementation entry of {@link MessagingAccessPoint}. */ - String DRIVER_IMPL = "DRIVER_IMPL"; - - /** - * The {@code ACCESS_POINTS} key shows the specified access points in OMS driver schema. - * - * @see Access Point - * Schema - */ - String ACCESS_POINTS = "ACCESS_POINTS"; + String DRIVER_IMPL = "driverImpl"; /** * The {@code ACCESS_KEY} key shows the specified access key in OMS driver schema. */ - String ACCESS_KEY = "AccessKey"; + String ACCESS_KEY = "accessKey"; /** * The {@code SECRET_KEY} key shows the specified secret key in OMS attribute. */ - String SECRET_KEY = "SecretKey"; + String SECRET_KEY = "secretKey"; /** * The {@code SECURITY_TOKEN} key shows the specified security token in OMS attribute. */ - String SECURITY_TOKEN = "SecurityToken"; + 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/api/TopicPartition.java b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java index e8add333..bb2358ff 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/TopicPartition.java @@ -17,7 +17,7 @@ package io.openmessaging.api; /** - * Used for describe a topic and + * Used for describe a topic * @version OMS 1.2.0 * @since OMS 1.2.0 */ @@ -80,4 +80,11 @@ public boolean equals(Object obj) { } return true; } + + @Override public String toString() { + return "TopicPartition{" + + "topic='" + topic + '\'' + + ", partition='" + partition + '\'' + + '}'; + } } diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java b/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.java deleted file mode 100644 index bb8b20b6..00000000 --- a/openmessaging-api/src/main/java/io/openmessaging/api/internal/AccessPointURI.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.api.internal; - -import io.openmessaging.api.OMSResponseStatus; - -import static io.openmessaging.api.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('/'); - String userAndHostInformation; - - if (idx != -1) { - this.region = unprocessedString.substring(idx + 1); - userAndHostInformation = unprocessedString.substring(0, idx); - } else { - this.region = null; - userAndHostInformation = unprocessedString; - } - - 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/api/internal/MessagingAccessPointAdapter.java b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java index 6555fc79..509e492a 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/internal/MessagingAccessPointAdapter.java @@ -37,23 +37,14 @@ 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, Properties 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); - if (accessPointURI.getRegion() != null) { - attributes.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion()); - } - if (accessPointURI.getAccountId() != null) { - attributes.put(OMSBuiltinKeys.ACCESS_KEY, accessPointURI.getAccountId()); - } try { Class driverImplClass = Class.forName(driverImpl); @@ -61,7 +52,7 @@ public static MessagingAccessPoint getMessagingAccessPoint(String url, Propertie MessagingAccessPoint vendorImpl = (MessagingAccessPoint) constructor.newInstance(attributes); return vendorImpl; } catch (Throwable e) { - throw generateException(OMSResponseStatus.STATUS_10000, url); + throw generateException(OMSResponseStatus.STATUS_10000); } } diff --git a/openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java b/openmessaging-api/src/test/java/io/openmessaging/api/internal/AccessPointURITest.java deleted file mode 100644 index 4ee08409..00000000 --- a/openmessaging-api/src/test/java/io/openmessaging/api/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.api.internal; - -import io.openmessaging.api.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 missHost = "oms:rocketmq://"; - try { - new AccessPointURI(missHost); - failBecauseExceptionWasNotThrown(OMSRuntimeException.class); - } catch (Exception e) { - assertThat(e).hasMessageContaining(String.format("The OMS driver URL [%s] is illegal.", missHost)); - } - } - - @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/api/internal/MessagingAccessPointAdapterTest.java b/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java index 045d863e..9f010026 100644 --- a/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java +++ b/openmessaging-api/src/test/java/io/openmessaging/api/internal/MessagingAccessPointAdapterTest.java @@ -20,7 +20,6 @@ import io.openmessaging.api.Consumer; import io.openmessaging.api.MessagingAccessPoint; import io.openmessaging.api.OMS; -import io.openmessaging.api.OMSBuiltinKeys; import io.openmessaging.api.Producer; import io.openmessaging.api.PullConsumer; import io.openmessaging.api.batch.BatchConsumer; @@ -36,11 +35,15 @@ public class MessagingAccessPointAdapterTest { @Test public void getMessagingAccessPoint() { - String testURI = "oms:test-vendor://alice@rocketmq.apache.org/us-east:default_space"; - Properties properties = new Properties(); - properties.put(OMSBuiltinKeys.DRIVER_IMPL, "io.openmessaging.api.internal.TestVendor"); - MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint(testURI, properties); + 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); } } From fedce3995ca2412aa9325a2d5865722e709e3c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9A=AE?= Date: Mon, 30 Dec 2019 12:22:42 +0800 Subject: [PATCH 16/23] Fix OMS#build(Properties) stackoverflow --- openmessaging-api/src/main/java/io/openmessaging/api/OMS.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java index 4ca3a212..908b1ed8 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/OMS.java @@ -142,7 +142,7 @@ public MessagingAccessPoint build(Properties config) { this.properties.put(entry.getKey(), entry.getValue()); } } - return this.build(properties); + return MessagingAccessPointAdapter.getMessagingAccessPoint(this.properties); } /** From 038a0a03846401e8079797759e15cd5790c80ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Mon, 30 Dec 2019 14:17:43 +0800 Subject: [PATCH 17/23] feat(pom) bump the version to 2.0.0-pubsub-SNAPSHOT --- openmessaging-admin/pom.xml | 2 +- openmessaging-api-samples/pom.xml | 6 +++--- openmessaging-api/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index d8b7e244..182bf278 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.2.0-SNAPSHOT + 2.0.0-pubsub-SNAPSHOT 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index c0f554ee..0985a57c 100644 --- a/openmessaging-api-samples/pom.xml +++ b/openmessaging-api-samples/pom.xml @@ -2,13 +2,13 @@ io.openmessaging parent - 1.2.0-SNAPSHOT + 2.0.0-pubsub-SNAPSHOT 4.0.0 jar openmessaging-api-samples - 1.2.0-SNAPSHOT + 2.0.0-pubsub-SNAPSHOT openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 1.2.0-SNAPSHOT + 2.0.0-pubsub-SNAPSHOT org.slf4j diff --git a/openmessaging-api/pom.xml b/openmessaging-api/pom.xml index 6747eb44..6e0f4546 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 1.2.0-SNAPSHOT + 2.0.0-pubsub-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 29db3d49..61cba7ae 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 1.2.0-SNAPSHOT + 2.0.0-pubsub-SNAPSHOT pom openmessaging From 0653977d8c032a88e4527cdbab6841b73e74e909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Tue, 14 Jan 2020 14:21:50 +0800 Subject: [PATCH 18/23] feat(oms-pubsub) add unified client manage Admin interface --- .../main/java/io/openmessaging/api/Admin.java | 30 +++++++++++++++++++ .../java/io/openmessaging/api/Consumer.java | 3 +- .../java/io/openmessaging/api/Producer.java | 2 +- .../io/openmessaging/api/PullConsumer.java | 2 +- .../api/batch/BatchConsumer.java | 5 ++-- .../api/order/OrderConsumer.java | 5 ++-- .../api/order/OrderProducer.java | 5 ++-- .../api/transaction/TransactionProducer.java | 5 ++-- 8 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 openmessaging-api/src/main/java/io/openmessaging/api/Admin.java 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/Consumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java index bb1c0948..4ed9cec0 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Consumer.java @@ -22,7 +22,7 @@ * @version OMS 1.2.0 * @since OMS 1.2.0 */ -public interface Consumer extends LifeCycle, Credentials { +public interface Consumer extends Admin { /** * Subscribe message in order. @@ -50,6 +50,7 @@ public interface Consumer extends LifeCycle, Credentials { /** * Unsubscribe message + * * @param topic */ void unsubscribe(final String topic); diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java index ba4e46fe..76573660 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Producer.java @@ -41,7 +41,7 @@ * @version OMS 1.2.0 * @since OMS 1.2.0 */ -public interface Producer extends LifeCycle, Credentials { +public interface Producer extends Admin { /** * Sends a message to the specified destination synchronously, the destination should be preset to {@link diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java index 15dbc9ad..e01cc8cd 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/PullConsumer.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Set; -public interface PullConsumer extends LifeCycle, Credentials { +public interface PullConsumer extends Admin { interface TopicPartitionChangeListener { /** 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 index da122ed9..0d624d81 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/batch/BatchConsumer.java @@ -17,8 +17,7 @@ package io.openmessaging.api.batch; -import io.openmessaging.api.Credentials; -import io.openmessaging.api.LifeCycle; +import io.openmessaging.api.Admin; /** * Batch message consumer, used to subscribe to messages in batch. @@ -26,7 +25,7 @@ * @version OMS 1.2.0 * @since OMS 1.2.0 */ -public interface BatchConsumer extends LifeCycle, Credentials { +public interface BatchConsumer extends Admin { /** * Subscribe message 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 index 0bd900e7..40d80be8 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderConsumer.java @@ -17,9 +17,8 @@ package io.openmessaging.api.order; -import io.openmessaging.api.Credentials; +import io.openmessaging.api.Admin; import io.openmessaging.api.ExpressionType; -import io.openmessaging.api.LifeCycle; import io.openmessaging.api.MessageSelector; /** @@ -28,7 +27,7 @@ * @version OMS 1.2.0 * @since OMS 1.2.0 */ -public interface OrderConsumer extends LifeCycle, Credentials { +public interface OrderConsumer extends Admin { /** * Subscribe message in order. 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 index f7d00e26..82d8e9b5 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/order/OrderProducer.java @@ -17,8 +17,7 @@ package io.openmessaging.api.order; -import io.openmessaging.api.Credentials; -import io.openmessaging.api.LifeCycle; +import io.openmessaging.api.Admin; import io.openmessaging.api.Message; import io.openmessaging.api.SendResult; @@ -28,7 +27,7 @@ * @version OMS 1.2.0 * @since OMS 1.2.0 */ -public interface OrderProducer extends LifeCycle, Credentials { +public interface OrderProducer extends Admin { /** * Send message in order 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 index 7e29a01e..99cf519b 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/transaction/TransactionProducer.java @@ -17,8 +17,7 @@ package io.openmessaging.api.transaction; -import io.openmessaging.api.Credentials; -import io.openmessaging.api.LifeCycle; +import io.openmessaging.api.Admin; import io.openmessaging.api.Message; import io.openmessaging.api.SendResult; @@ -28,7 +27,7 @@ * @version OMS 1.2.0 * @since OMS 1.2.0 */ -public interface TransactionProducer extends LifeCycle, Credentials { +public interface TransactionProducer extends Admin { /** * This method is used to send a transactional message. A transactional message is sent in three steps: From 026789be4bb265d7390d395c789d05b66693ab39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Tue, 14 Jan 2020 17:22:12 +0800 Subject: [PATCH 19/23] [maven-release-plugin] prepare release parent-2.0.0-pubsub --- openmessaging-admin/pom.xml | 2 +- openmessaging-api-samples/pom.xml | 6 +++--- openmessaging-api/pom.xml | 2 +- pom.xml | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index 182bf278..1ed9612f 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.0-pubsub-SNAPSHOT + 2.0.0-pubsub 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index 0985a57c..0e7a1707 100644 --- a/openmessaging-api-samples/pom.xml +++ b/openmessaging-api-samples/pom.xml @@ -2,13 +2,13 @@ io.openmessaging parent - 2.0.0-pubsub-SNAPSHOT + 2.0.0-pubsub 4.0.0 jar openmessaging-api-samples - 2.0.0-pubsub-SNAPSHOT + 2.0.0-pubsub openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 2.0.0-pubsub-SNAPSHOT + 2.0.0-pubsub org.slf4j diff --git a/openmessaging-api/pom.xml b/openmessaging-api/pom.xml index 6e0f4546..ffb415bd 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.0-pubsub-SNAPSHOT + 2.0.0-pubsub 4.0.0 diff --git a/pom.xml b/pom.xml index 61cba7ae..c17e5f73 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 2.0.0-pubsub-SNAPSHOT + 2.0.0-pubsub pom openmessaging @@ -123,6 +123,7 @@ UTF-8 en_US io.openmessaging.api.internal + -Xdoclint:none From 3e999d6bea2cdb48d7f34394482262e41a3e0797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Tue, 14 Jan 2020 17:23:01 +0800 Subject: [PATCH 20/23] [maven-release-plugin] prepare for next development iteration --- openmessaging-admin/pom.xml | 2 +- openmessaging-api-samples/pom.xml | 6 +++--- openmessaging-api/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index 1ed9612f..771e2247 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.0-pubsub + 2.0.1-pubsub-SNAPSHOT 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index 0e7a1707..e3550ab6 100644 --- a/openmessaging-api-samples/pom.xml +++ b/openmessaging-api-samples/pom.xml @@ -2,13 +2,13 @@ io.openmessaging parent - 2.0.0-pubsub + 2.0.1-pubsub-SNAPSHOT 4.0.0 jar openmessaging-api-samples - 2.0.0-pubsub + 2.0.1-pubsub-SNAPSHOT openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 2.0.0-pubsub + 2.0.1-pubsub-SNAPSHOT org.slf4j diff --git a/openmessaging-api/pom.xml b/openmessaging-api/pom.xml index ffb415bd..d843b839 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.0-pubsub + 2.0.1-pubsub-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index c17e5f73..7739fb37 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 2.0.0-pubsub + 2.0.1-pubsub-SNAPSHOT pom openmessaging From df8d962f2e8603dc2b806c64729f2576e019693b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Mon, 16 Mar 2020 20:53:52 +0800 Subject: [PATCH 21/23] feat(message) add offset and partion meta data --- .../java/io/openmessaging/api/Message.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/openmessaging-api/src/main/java/io/openmessaging/api/Message.java b/openmessaging-api/src/main/java/io/openmessaging/api/Message.java index 23ac4175..ad5d4256 100644 --- a/openmessaging-api/src/main/java/io/openmessaging/api/Message.java +++ b/openmessaging-api/src/main/java/io/openmessaging/api/Message.java @@ -237,6 +237,28 @@ 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=" @@ -253,5 +275,9 @@ static public class SystemPropKey { public static final String BORNHOST = "__BORNHOST"; public static final String STARTDELIVERTIME = "__STARTDELIVERTIME"; + + public static final String CONSUMEOFFSET = "__CONSUMEOFFSET"; + + public static final String PARTITION = "__PARTITION"; } } From 416e44f13cef2d55dd9a6c233892660da434a857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Sat, 21 Mar 2020 20:06:56 +0800 Subject: [PATCH 22/23] [maven-release-plugin] prepare release parent-2.0.1-pubsub --- openmessaging-admin/pom.xml | 2 +- openmessaging-api-samples/pom.xml | 6 +++--- openmessaging-api/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index 771e2247..4dfe8d34 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.1-pubsub-SNAPSHOT + 2.0.1-pubsub 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index e3550ab6..9009b9e6 100644 --- a/openmessaging-api-samples/pom.xml +++ b/openmessaging-api-samples/pom.xml @@ -2,13 +2,13 @@ io.openmessaging parent - 2.0.1-pubsub-SNAPSHOT + 2.0.1-pubsub 4.0.0 jar openmessaging-api-samples - 2.0.1-pubsub-SNAPSHOT + 2.0.1-pubsub openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 2.0.1-pubsub-SNAPSHOT + 2.0.1-pubsub org.slf4j diff --git a/openmessaging-api/pom.xml b/openmessaging-api/pom.xml index d843b839..64ebf289 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.1-pubsub-SNAPSHOT + 2.0.1-pubsub 4.0.0 diff --git a/pom.xml b/pom.xml index 7739fb37..2da6a455 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 2.0.1-pubsub-SNAPSHOT + 2.0.1-pubsub pom openmessaging From dc46f8296603a94c3a547d9cfee630b91d3fd3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=8A=E5=90=8D?= Date: Sat, 21 Mar 2020 20:07:25 +0800 Subject: [PATCH 23/23] [maven-release-plugin] prepare for next development iteration --- openmessaging-admin/pom.xml | 2 +- openmessaging-api-samples/pom.xml | 6 +++--- openmessaging-api/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openmessaging-admin/pom.xml b/openmessaging-admin/pom.xml index 4dfe8d34..9b172e46 100644 --- a/openmessaging-admin/pom.xml +++ b/openmessaging-admin/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.1-pubsub + 2.0.2-pubsub-SNAPSHOT 4.0.0 diff --git a/openmessaging-api-samples/pom.xml b/openmessaging-api-samples/pom.xml index 9009b9e6..f62c70f1 100644 --- a/openmessaging-api-samples/pom.xml +++ b/openmessaging-api-samples/pom.xml @@ -2,13 +2,13 @@ io.openmessaging parent - 2.0.1-pubsub + 2.0.2-pubsub-SNAPSHOT 4.0.0 jar openmessaging-api-samples - 2.0.1-pubsub + 2.0.2-pubsub-SNAPSHOT openmessaging-api-samples ${project.version} @@ -21,7 +21,7 @@ ${project.groupId} openmessaging-api - 2.0.1-pubsub + 2.0.2-pubsub-SNAPSHOT org.slf4j diff --git a/openmessaging-api/pom.xml b/openmessaging-api/pom.xml index 64ebf289..bd53ce6c 100644 --- a/openmessaging-api/pom.xml +++ b/openmessaging-api/pom.xml @@ -2,7 +2,7 @@ io.openmessaging parent - 2.0.1-pubsub + 2.0.2-pubsub-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 2da6a455..2e1269fc 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.openmessaging parent - 2.0.1-pubsub + 2.0.2-pubsub-SNAPSHOT pom openmessaging