Skip to content

Commit a5c225b

Browse files
authored
Add examples for different subscription modes (#9)
*Motivation* Add examples to demonstrate different subscription modes
1 parent 70c77bd commit a5c225b

File tree

17 files changed

+534
-23
lines changed

17 files changed

+534
-23
lines changed

.github/workflows/clients.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
#
14+
15+
name: Clients
16+
on:
17+
pull_request:
18+
branches:
19+
- master
20+
paths:
21+
- 'clients/*'
22+
23+
jobs:
24+
25+
clients:
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 120
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v2
32+
33+
- name: Set up JDK 1.8
34+
uses: actions/setup-java@v1
35+
with:
36+
java-version: 1.8
37+
38+
- name: Set up Maven
39+
uses: apache/pulsar-test-infra/setup-maven@master
40+
with:
41+
maven-version: 3.6.1
42+
43+
- name: run maven test
44+
run: |
45+
cd clients
46+
mvn license:check checkstyle:check install

clients/common/src/main/java/io/streamnative/examples/common/ConsumerFlags.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.beust.jcommander.Parameter;
1717
import org.apache.pulsar.client.api.SubscriptionInitialPosition;
1818
import org.apache.pulsar.client.api.SubscriptionType;
19+
import org.apache.pulsar.common.api.proto.PulsarApi.CommandAck.AckType;
1920

2021
/**
2122
* Common flags for a consumer example.
@@ -48,4 +49,20 @@ public class ConsumerFlags extends TopicFlags {
4849
)
4950
public SubscriptionInitialPosition subscriptionInitialPosition = SubscriptionInitialPosition.Earliest;
5051

52+
@Parameter(
53+
names = {
54+
"-an", "--ack-every-n-messages"
55+
},
56+
description = "Ack every N messages"
57+
)
58+
public int ackEveryNMessages = 1;
59+
60+
@Parameter(
61+
names = {
62+
"-at", "--ack-type"
63+
},
64+
description = "Ack type"
65+
)
66+
public AckType ackType = null;
67+
5168
}

clients/common/src/main/java/io/streamnative/examples/common/ProducerFlags.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@
1313
*/
1414
package io.streamnative.examples.common;
1515

16+
import com.beust.jcommander.Parameter;
17+
1618
/**
1719
* Common flags for running a producer example.
1820
*/
1921
public class ProducerFlags extends TopicFlags {
22+
23+
@Parameter(
24+
names = {
25+
"-r", "--messages-rate"
26+
},
27+
description = "Messages rate to produce"
28+
)
29+
public double rate = -1;
30+
2031
}

clients/common/src/main/java/io/streamnative/examples/common/PulsarClientFlags.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.apache.bookkeeper.tools.framework.CliFlags;
1818

1919
/**
20-
* Default example flags
20+
* Default example flags.
2121
*/
2222
public class PulsarClientFlags extends CliFlags {
2323

clients/common/src/main/java/io/streamnative/examples/common/TopicFlags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,12 @@ public class TopicFlags extends PulsarClientFlags {
3737
)
3838
public int numMessages = 10;
3939

40+
@Parameter(
41+
names = {
42+
"-nk", "--num-keys"
43+
},
44+
description = "Number of keys"
45+
)
46+
public int numKeys = 128;
47+
4048
}

clients/pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,27 @@
6060
<testRetryCount>2</testRetryCount>
6161

6262
<!-- dependencies -->
63-
<avro.version>1.8.2</avro.version>
64-
<bookkeeper.version>4.9.2</bookkeeper.version>
63+
<avro.version>1.9.1</avro.version>
64+
<bookkeeper.version>4.10.0</bookkeeper.version>
6565
<google.code.version>3.0.2</google.code.version>
6666
<google.errorprone.version>2.1.2</google.errorprone.version>
6767
<grpc.version>1.18.0</grpc.version>
68-
<guava.version>21.0</guava.version>
68+
<guava.version>25.1-jre</guava.version>
6969
<hamcrest.version>1.3</hamcrest.version>
7070
<joda.version>2.7</joda.version>
7171
<jmh.version>1.19</jmh.version>
7272
<jmock.version>2.8.2</jmock.version>
7373
<junit.version>4.12</junit.version>
7474
<lombok.version>1.16.22</lombok.version>
7575
<mockito.version>2.22.0</mockito.version>
76-
<netty.version>4.1.32.Final</netty.version>
77-
<netty-boringssl.version>2.0.20.Final</netty-boringssl.version>
76+
<netty.version>4.1.48.Final</netty.version>
77+
<netty-boringssl.version>2.0.30.Final</netty-boringssl.version>
7878
<powermock.version>2.0.0-beta.5</powermock.version>
7979
<protobuf3.version>3.5.1</protobuf3.version>
8080
<protoc3.version>3.5.1-1</protoc3.version>
8181
<protoc-gen-grpc-java.version>1.12.0</protoc-gen-grpc-java.version>
8282
<!-- latest version from apache pulsar master -->
83-
<pulsar.version>2.4.0</pulsar.version>
83+
<pulsar.version>2.5.2</pulsar.version>
8484
<slf4j.version>1.7.25</slf4j.version>
8585
<spotbugs-annotations.version>3.1.8</spotbugs-annotations.version>
8686
<javax-annotations-api.version>1.3.2</javax-annotations-api.version>

clients/pubsub/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@
4646

4747
<build>
4848
<plugins>
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-assembly-plugin</artifactId>
52+
<configuration>
53+
<!-- get all project dependencies -->
54+
<descriptorRefs>
55+
<descriptorRef>jar-with-dependencies</descriptorRef>
56+
</descriptorRefs>
57+
<finalName>pulsar-pubsub-examples</finalName>
58+
<appendAssemblyId>false</appendAssemblyId>
59+
</configuration>
60+
<executions>
61+
<execution>
62+
<id>make-assembly</id>
63+
<!-- bind to the packaging phase -->
64+
<phase>package</phase>
65+
<goals>
66+
<goal>single</goal>
67+
</goals>
68+
</execution>
69+
</executions>
70+
</plugin>
4971
</plugins>
5072
</build>
5173
</project>

clients/pubsub/src/main/java/io/streamnative/examples/pubsub/DeadLetterTopicConsumerExample.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/**
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
114
/**
215
* Licensed under the Apache License, Version 2.0 (the "License");
316
* you may not use this file except in compliance with the License.
@@ -15,9 +28,14 @@
1528

1629
import io.streamnative.examples.common.ConsumerFlags;
1730
import io.streamnative.examples.common.ExampleRunner;
18-
import org.apache.pulsar.client.api.*;
1931

2032
import java.util.concurrent.TimeUnit;
33+
import org.apache.pulsar.client.api.Consumer;
34+
import org.apache.pulsar.client.api.DeadLetterPolicy;
35+
import org.apache.pulsar.client.api.Message;
36+
import org.apache.pulsar.client.api.PulsarClient;
37+
import org.apache.pulsar.client.api.PulsarClientException;
38+
import org.apache.pulsar.client.api.Schema;
2139

2240
/**
2341
* Example that demonstrates how to use dead letter topic.

clients/pubsub/src/main/java/io/streamnative/examples/pubsub/DelayedAfterMessageProducerExample.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515

1616
import io.streamnative.examples.common.ExampleRunner;
1717
import io.streamnative.examples.common.ProducerFlags;
18-
import org.apache.commons.lang.time.DateUtils;
18+
import java.util.concurrent.TimeUnit;
1919
import org.apache.pulsar.client.api.Producer;
2020
import org.apache.pulsar.client.api.PulsarClient;
2121
import org.apache.pulsar.client.api.Schema;
2222

23-
import java.util.Date;
24-
import java.util.concurrent.TimeUnit;
25-
2623
/**
2724
* Example that demonstrates how to use delayed message delivery feature.
2825
**/

clients/pubsub/src/main/java/io/streamnative/examples/pubsub/DelayedAtMessageProducerExample.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515

1616
import io.streamnative.examples.common.ExampleRunner;
1717
import io.streamnative.examples.common.ProducerFlags;
18+
import java.util.Date;
1819
import org.apache.commons.lang.time.DateUtils;
1920
import org.apache.pulsar.client.api.Producer;
2021
import org.apache.pulsar.client.api.PulsarClient;
2122
import org.apache.pulsar.client.api.Schema;
2223

23-
import java.util.Date;
24-
2524
/**
2625
* Example that demonstrates how to use delayed message delivery feature.
2726
**/

0 commit comments

Comments
 (0)