-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSimpleTopicExample.java
40 lines (33 loc) · 1.22 KB
/
SimpleTopicExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package tech.ydb.examples.topic;
import tech.ydb.auth.iam.CloudAuthHelper;
import tech.ydb.core.grpc.GrpcTransport;
/**
* @author Nikolay Perfilov
*/
public abstract class SimpleTopicExample {
protected static final String TOPIC_NAME = System.getenv("YDB_TOPIC_NAME");
protected static final String CONSUMER_NAME = System.getenv("YDB_CONSUMER_NAME");
protected void doMain(String[] args) {
if (args.length > 1) {
System.err.println("Too many arguments");
return;
}
String connString;
if (args.length == 1) {
connString = args[0];
} else {
System.err.println("Pass <connection-string> as an argument. " +
"Example: some.host.name.com:2135?database=/Root\n");
return;
}
System.out.println("connection-string: " + connString + "\n");
try (GrpcTransport transport = GrpcTransport.forConnectionString(connString)
.withAuthProvider(CloudAuthHelper.getAuthProviderFromEnviron())
.build()) {
run(transport);
} catch (Throwable t) {
t.printStackTrace();
}
}
protected abstract void run(GrpcTransport transport);
}