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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
DMaaP Client based API
======================
ONAP Gerrit repo: \ https://gerrit.onap.org/r/#/admin/projects/aai/event-client
This is a thin API library based on the DMaaP Client, and exposes
methods that can be used to publish and consume JSON messages to/from a
DMaaP topic.
Importing the library
=====================
To add the Event Bus Client Library to your project simply include the
following dependencies in your project's pom.xml. Note that
the httpclient dependency may be required in your project pom if you are
also depending on AJSC artifacts, as they use an earlier version of
the httpclient which may overwrite the later version required by the
library.
<dependency>
<groupId>org.onap.aai.event-client</groupId>
<artifactId>event-client-dmaap</artifactId>
<version>1.2.0-SNAPSHOT</version>
</dependency>
<!-- This dependency is required if you also have AJSC dependencies -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<!-- This dependency is required if you also have AJSC dependencies -->
**Note** - In order to retrieve all of the client's transitive
dependencies you may need to configure your maven settings.xml with the
ONAP repositories.
Publishing
==========
Here is an example of how to use the client to publish a message to the
DMaaP topic.
DMaaPEventPublisher eventPublisher = new DMaaPEventPublisher(host,
topic, username, password);
try {
int result = eventPublisher.sendSync(partition, messages);
// result should equal number of messages supplied to sendSync
} catch (...) {
} finally {
List<String> unsentMessages = eventPublisher.closeWithUnsent()
// Handle unsent messages
}
**host** - The host URL to use to connect to the DMaaP topic, in the
form of <host:port>.
**topic** - The topic name to publish to. This must be an existing DMaaP
topic.
**username** - The MechID of the calling application.
**password** - The password for the MechID.
**partition** - The partition to publish the message to.
**message** - A List of JSON String messages to publish as a batch.
Consuming
---------
Here is an example of how to use the client to consume messages from the
UEB.
try {
DMaaPEventConsumer consumer = new DMaaPEventConsumer(host, topic,
username, password, consumerGroup, consumerId)
Iterable<String> messages = consumer.consume();
for(String message : messages) {
// process message
}
} catch(...) {}
**host** - The host URL to use to connect to the DMaaP topic, in the
form of <host:port>.
**topic** - The topic name to consume from. This must be an existing
topic.
**username** - The MechID of the calling application.
**password** - The password for the MechID.
**consumerGroup** - The name of the consumer group this consumer is part
of.
**consumerId** - The unique id of this consumer in its group.
Creating Topics and Authentication
==================================
For information about creating and managing DMaaP topics, refer to the
`DMaaP DBCAPI <https://gerrit.onap.org/r/#/admin/projects/dmaap/dbcapi>`__
project documentation.
|