Skip to content

Commit 3509172

Browse files
authored
Merge pull request #2 from openmessaging/master
merge
2 parents 941bda1 + 44b95ce commit 3509172

33 files changed

+892
-483
lines changed

openmessaging-admin/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<parent>
33
<groupId>io.openmessaging</groupId>
44
<artifactId>parent</artifactId>
5-
<version>1.0.0-preview</version>
5+
<version>1.0.0-beta-SNAPSHOT</version>
66
</parent>
77

88
<modelVersion>4.0.0</modelVersion>

openmessaging-api-samples/pom.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
<parent>
33
<groupId>io.openmessaging</groupId>
44
<artifactId>parent</artifactId>
5-
<version>1.0.0-preview</version>
5+
<version>1.0.0-beta-SNAPSHOT</version>
66
</parent>
77

88
<modelVersion>4.0.0</modelVersion>
99
<packaging>jar</packaging>
1010
<artifactId>openmessaging-api-samples</artifactId>
11+
<version>1.0.0-beta-SNAPSHOT</version>
1112
<name>openmessaging-api-samples ${project.version}</name>
1213

1314
<dependencies>
@@ -20,7 +21,7 @@
2021
<dependency>
2122
<groupId>${project.groupId}</groupId>
2223
<artifactId>openmessaging-api</artifactId>
23-
<version>${project.version}</version>
24+
<version>1.0.0-beta-SNAPSHOT</version>
2425
</dependency>
2526
<dependency>
2627
<groupId>org.slf4j</groupId>

openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PullConsumerApp.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,19 @@
1717

1818
package io.openmessaging.samples.consumer;
1919

20-
import io.openmessaging.Message;
2120
import io.openmessaging.MessagingAccessPoint;
2221
import io.openmessaging.OMS;
2322
import io.openmessaging.consumer.Consumer;
24-
import io.openmessaging.manager.ResourceManager;
23+
import io.openmessaging.message.Message;
2524

2625
public class PullConsumerApp {
2726
public static void main(String[] args) {
2827
//Load and start the vendor implementation from a specific OMS driver URL.
2928
final MessagingAccessPoint messagingAccessPoint =
3029
OMS.getMessagingAccessPoint("oms:rocketmq://[email protected]/us-east");
3130

32-
//Fetch a ResourceManager to create Queue resource.
33-
ResourceManager resourceManager = messagingAccessPoint.resourceManager();
34-
resourceManager.createQueue("NS://HELLO_QUEUE");
35-
3631
//Start a PullConsumer to receive messages from the specific queue.
3732
final Consumer consumer = messagingAccessPoint.createConsumer();
38-
consumer.start();
3933

4034
//Register a shutdown hook to close the opened endpoints.
4135
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@@ -44,10 +38,15 @@ public void run() {
4438
consumer.stop();
4539
}
4640
}));
41+
4742
consumer.bindQueue("NS://HELLO_QUEUE");
43+
consumer.start();
44+
4845
Message message = consumer.receive(1000);
4946
System.out.println("Received message: " + message);
5047
//Acknowledge the consumed message
51-
consumer.ack(message.headers().getMessageId());
48+
consumer.ack(message.getMessageReceipt());
49+
consumer.stop();
50+
5251
}
5352
}

openmessaging-api-samples/src/main/java/io/openmessaging/samples/consumer/PushConsumerApp.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
package io.openmessaging.samples.consumer;
1919

20-
import io.openmessaging.Message;
2120
import io.openmessaging.MessagingAccessPoint;
2221
import io.openmessaging.OMS;
2322
import io.openmessaging.consumer.Consumer;
2423
import io.openmessaging.consumer.MessageListener;
2524
import io.openmessaging.manager.ResourceManager;
25+
import io.openmessaging.message.Message;
2626

2727
public class PushConsumerApp {
2828
public static void main(String[] args) {

openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/ProducerApp.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
package io.openmessaging.samples.producer;
1919

2020
import io.openmessaging.Future;
21-
import io.openmessaging.Message;
2221
import io.openmessaging.MessagingAccessPoint;
2322
import io.openmessaging.OMS;
2423
import io.openmessaging.interceptor.Context;
2524
import io.openmessaging.interceptor.ProducerInterceptor;
25+
import io.openmessaging.message.Message;
2626
import io.openmessaging.producer.Producer;
2727
import io.openmessaging.producer.SendResult;
2828
import java.nio.charset.Charset;
@@ -35,17 +35,19 @@ public static void main(String[] args) {
3535
OMS.getMessagingAccessPoint("oms:rocketmq://[email protected]/us-east");
3636

3737
final Producer producer = messagingAccessPoint.createProducer();
38-
producer.start();
3938
ProducerInterceptor interceptor = new ProducerInterceptor() {
4039
@Override
4140
public void preSend(Message message, Context attributes) {
41+
System.out.println("PreSend message: " + message);
4242
}
4343

4444
@Override
4545
public void postSend(Message message, Context attributes) {
46+
System.out.println("PostSend message: " + message);
4647
}
4748
};
4849
producer.addInterceptor(interceptor);
50+
producer.start();
4951

5052
//Register a shutdown hook to close the opened endpoints.
5153
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@@ -55,9 +57,11 @@ public void run() {
5557
}
5658
}));
5759

58-
//Sends a message to the specified destination synchronously.
60+
//Send a message to the specified destination synchronously.
5961
Message message = producer.createMessage(
60-
"NS://HELLO_QUEUE", "HELLO_BODY".getBytes(Charset.forName("UTF-8")));
62+
"NS://HELLO_QUEUE1", "HELLO_BODY".getBytes(Charset.forName("UTF-8")));
63+
message.header().setBornHost("127.0.0.1").setDurability((short) 0);
64+
message.extensionHeader().get().setPartition(1);
6165
SendResult sendResult = producer.send(message);
6266
System.out.println("SendResult: " + sendResult);
6367

@@ -75,6 +79,7 @@ public void run() {
7579
Message msg = producer.createMessage("NS://HELLO_QUEUE", ("Hello" + i).getBytes());
7680
messages.add(msg);
7781
}
82+
7883
producer.send(messages);
7984
producer.removeInterceptor(interceptor);
8085
producer.stop();

openmessaging-api-samples/src/main/java/io/openmessaging/samples/producer/TransactionProducerApp.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package io.openmessaging.samples.producer;
1919

20-
import io.openmessaging.Message;
20+
import io.openmessaging.message.Message;
2121
import io.openmessaging.MessagingAccessPoint;
2222
import io.openmessaging.OMS;
2323
import io.openmessaging.producer.Producer;

openmessaging-api-samples/src/main/java/io/openmessaging/samples/routing/RoutingApp.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package io.openmessaging.samples.routing;
1919

20-
import io.openmessaging.Message;
20+
import io.openmessaging.message.Message;
2121
import io.openmessaging.MessagingAccessPoint;
2222
import io.openmessaging.OMS;
2323
import io.openmessaging.consumer.Consumer;

openmessaging-api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<parent>
33
<groupId>io.openmessaging</groupId>
44
<artifactId>parent</artifactId>
5-
<version>1.0.0-preview</version>
5+
<version>1.0.0-beta-SNAPSHOT</version>
66
</parent>
77

88
<modelVersion>4.0.0</modelVersion>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.openmessaging;
18+
19+
import io.openmessaging.extension.Extension;
20+
import java.util.Optional;
21+
22+
/**
23+
* <p>
24+
* A {@code Client} interface contains all the common behaviors of producer and consumer. which can be used to achieve
25+
* some basic interaction with the server.
26+
* </p>
27+
*
28+
* @version OMS 1.0.0
29+
* @since OMS 1.0.0
30+
*/
31+
public interface Client {
32+
/**
33+
* Get the extension method, and this interface is optional, Therefore, users need to check whether this interface
34+
* has been implemented by vendors.
35+
* <p>
36+
*
37+
* @return the implementation of {@link Extension}
38+
*/
39+
@io.openmessaging.annotation.Optional
40+
Optional<Extension> getExtension();
41+
}

openmessaging-api/src/main/java/io/openmessaging/KeyValue.java

+29-33
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
*/
3636
public interface KeyValue {
3737

38+
/**
39+
* Inserts or replaces {@code boolean} value for the specified key.
40+
*
41+
* @param key the key to be placed into this {@code KeyValue} object
42+
* @param value the value corresponding to <tt>key</tt>
43+
*/
44+
KeyValue put(String key, boolean value);
45+
3846
/**
3947
* Inserts or replaces {@code short} value for the specified key.
4048
*
@@ -75,6 +83,27 @@ public interface KeyValue {
7583
*/
7684
KeyValue put(String key, String value);
7785

86+
/**
87+
* Searches for the {@code boolean} property with the specified key in this {@code KeyValue} object. If the key is
88+
* not found in this property list, false is returned.
89+
*
90+
* @param key the property key
91+
* @return the value in this {@code KeyValue} object with the specified key value
92+
* @see #put(String, boolean)
93+
*/
94+
boolean getBoolean(String key);
95+
96+
/**
97+
* Searches for the {@code boolean} property with the specified key in this {@code KeyValue} object. If the key is
98+
* not found in this property list, false is returned.
99+
*
100+
* @param key the property key
101+
* @param defaultValue a default value
102+
* @return the value in this {@code KeyValue} object with the specified key value
103+
* @see #put(String, boolean)
104+
*/
105+
boolean getBoolean(String key, boolean defaultValue);
106+
78107
/**
79108
* Searches for the {@code short} property with the specified key in this {@code KeyValue} object. If the key is not
80109
* found in this property list, zero is returned.
@@ -106,17 +135,6 @@ public interface KeyValue {
106135
*/
107136
int getInt(String key);
108137

109-
/**
110-
* Searches for the {@code int} property with the specified key in this {@code KeyValue} object. If the key is not
111-
* found in this property list, the default value argument is returned.
112-
*
113-
* @param key the property key
114-
* @param defaultValue a default value
115-
* @return the value in this {@code KeyValue} object with the specified key value
116-
* @see #put(String, int)
117-
*/
118-
int getInt(String key, int defaultValue);
119-
120138
/**
121139
* Searches for the {@code long} property with the specified key in this {@code KeyValue} object. If the key is not
122140
* found in this property list, zero is returned.
@@ -148,17 +166,6 @@ public interface KeyValue {
148166
*/
149167
double getDouble(String key);
150168

151-
/**
152-
* Searches for the {@code double} property with the specified key in this {@code KeyValue} object. If the key is
153-
* not found in this property list, the default value argument is returned.
154-
*
155-
* @param key the property key
156-
* @param defaultValue a default value
157-
* @return the value in this {@code KeyValue} object with the specified key value
158-
* @see #put(String, double)
159-
*/
160-
double getDouble(String key, double defaultValue);
161-
162169
/**
163170
* Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is
164171
* not found in this property list, {@code null} is returned.
@@ -169,17 +176,6 @@ public interface KeyValue {
169176
*/
170177
String getString(String key);
171178

172-
/**
173-
* Searches for the {@code String} property with the specified key in this {@code KeyValue} object. If the key is
174-
* not found in this property list, the default value argument is returned.
175-
*
176-
* @param key the property key
177-
* @param defaultValue a default value
178-
* @return the value in this {@code KeyValue} object with the specified key value
179-
* @see #put(String, String)
180-
*/
181-
String getString(String key, String defaultValue);
182-
183179
/**
184180
* Returns a {@link Set} view of the keys contained in this {@code KeyValue} object.
185181
* <p>

0 commit comments

Comments
 (0)