[ROCKETMQ-17] Develop a vendor-neutral open standard for distributed messaging: 
Add the asynchronous send message samples
ASF JIRA: https://issues.apache.org/jira/browse/ROCKETMQ-17


Project: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/commit/602dafc0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/tree/602dafc0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/diff/602dafc0

Branch: refs/heads/spec
Commit: 602dafc0dcecd189bc9362a73793629e48600dce
Parents: 86f4e26
Author: vintagewang <[email protected]>
Authored: Sun Jan 1 20:12:13 2017 +0800
Committer: vintagewang <[email protected]>
Committed: Sun Jan 1 20:12:13 2017 +0800

----------------------------------------------------------------------
 .../openmessaging/samples/ProducerApp.java      | 55 ---------------
 .../samples/async/ProducerApp.java              | 72 ++++++++++++++++++++
 .../samples/simple/ProducerApp.java             | 56 +++++++++++++++
 3 files changed, 128 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/602dafc0/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/ProducerApp.java
----------------------------------------------------------------------
diff --git 
a/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/ProducerApp.java
 
b/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/ProducerApp.java
deleted file mode 100644
index 897365a..0000000
--- 
a/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/ProducerApp.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 org.apache.openmessaging.samples;
-
-import java.nio.charset.Charset;
-import org.apache.openmessaging.MessagingEndPoint;
-import org.apache.openmessaging.MessagingEndPointManager;
-import org.apache.openmessaging.Producer;
-
-public class ProducerApp {
-    public static void main(String[] args) {
-        final MessagingEndPoint messagingEndPoint = 
MessagingEndPointManager.getMessagingEndPoint("openmessaging:rocketmq://localhost:10911/namespace");
-
-        final Producer producer = messagingEndPoint.createProducer();
-
-        messagingEndPoint.start();
-        System.out.println("messagingEndPoint startup OK");
-
-        producer.start();
-        System.out.println("producer startup OK");
-
-        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
-            @Override
-            public void run() {
-                producer.shutdown();
-                messagingEndPoint.shutdown();
-            }
-        }));
-
-        producer.send(producer.createBytesMessage("HELLO_TOPIC", 
"HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
-        System.out.println("send first message OK");
-
-        producer.send(producer.createBytesMessage("HELLO_TOPIC", 
"HELLO_BODY".getBytes(Charset.forName("UTF-8")))
-            .putProperties("KEY1", 100)//
-            .putProperties("KEY2", 200L)//
-            .putProperties("KEY3", 3.14)//
-            .putProperties("KEY4", "value4")//
-        );
-        System.out.println("send second message OK");
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/602dafc0/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/async/ProducerApp.java
----------------------------------------------------------------------
diff --git 
a/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/async/ProducerApp.java
 
b/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/async/ProducerApp.java
new file mode 100644
index 0000000..7c519cd
--- /dev/null
+++ 
b/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/async/ProducerApp.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openmessaging.samples.async;
+
+import java.nio.charset.Charset;
+import org.apache.openmessaging.MessagingEndPoint;
+import org.apache.openmessaging.MessagingEndPointManager;
+import org.apache.openmessaging.Producer;
+import org.apache.openmessaging.Promise;
+import org.apache.openmessaging.PromiseListener;
+
+public class ProducerApp {
+    public static void main(String[] args) {
+        final MessagingEndPoint messagingEndPoint = 
MessagingEndPointManager.getMessagingEndPoint("openmessaging:rocketmq://localhost:10911/namespace");
+
+        final Producer producer = messagingEndPoint.createProducer();
+
+        messagingEndPoint.start();
+        System.out.println("messagingEndPoint startup OK");
+
+        producer.start();
+        System.out.println("producer startup OK");
+
+        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+            @Override
+            public void run() {
+                producer.shutdown();
+                messagingEndPoint.shutdown();
+            }
+        }));
+
+        {
+            final Promise<Void> result = 
producer.sendAsync(producer.createBytesMessage("HELLO_TOPIC", 
"HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
+            final Void aVoid = result.get(3000L);
+            System.out.println("send async message OK");
+        }
+
+        {
+            final Promise<Void> result = 
producer.sendAsync(producer.createBytesMessage("HELLO_TOPIC", 
"HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
+            result.addListener(new PromiseListener<Void>() {
+                @Override public void operationComplete(Promise<Void> promise) 
{
+                    System.out.println("send async message OK");
+                }
+
+                @Override public void operationFailed(Promise<Void> promise) {
+                    System.out.println("send async message Failed");
+                }
+            });
+
+            System.out.println("send async message OK");
+        }
+
+        {
+            producer.sendOneway(producer.createBytesMessage("HELLO_TOPIC", 
"HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
+            System.out.println("send oneway message OK");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/602dafc0/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/simple/ProducerApp.java
----------------------------------------------------------------------
diff --git 
a/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/simple/ProducerApp.java
 
b/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/simple/ProducerApp.java
new file mode 100644
index 0000000..4460345
--- /dev/null
+++ 
b/spec/code/messaging-user-level-samples/java/src/main/java/org/apache/openmessaging/samples/simple/ProducerApp.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.openmessaging.samples.simple;
+
+import java.nio.charset.Charset;
+import org.apache.openmessaging.MessagingEndPoint;
+import org.apache.openmessaging.MessagingEndPointManager;
+import org.apache.openmessaging.Producer;
+
+public class ProducerApp {
+    public static void main(String[] args) {
+        final MessagingEndPoint messagingEndPoint = 
MessagingEndPointManager.getMessagingEndPoint("openmessaging:rocketmq://localhost:10911/namespace");
+
+        final Producer producer = messagingEndPoint.createProducer();
+
+        messagingEndPoint.start();
+        System.out.println("messagingEndPoint startup OK");
+
+        producer.start();
+        System.out.println("producer startup OK");
+
+        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+            @Override
+            public void run() {
+                producer.shutdown();
+                messagingEndPoint.shutdown();
+            }
+        }));
+
+        producer.send(producer.createBytesMessage("HELLO_TOPIC", 
"HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
+        System.out.println("send first message OK");
+
+        producer.send(producer.createBytesMessage("HELLO_TOPIC", 
"HELLO_BODY".getBytes(Charset.forName("UTF-8")))
+            .putProperties("KEY1", 100)//
+            .putProperties("KEY2", 200L)//
+            .putProperties("KEY3", 3.14)//
+            .putProperties("KEY4", "value4")//
+        );
+        System.out.println("send second message OK");
+    }
+}
\ No newline at end of file

Reply via email to