@@ -72,7 +72,7 @@ This code creates a producer client object that's used to produce/send events to
72
72
``` java
73
73
EventHubProducerClient producer = new EventHubClientBuilder ()
74
74
.connectionString(connectionString, eventHubName)
75
- .buildProducer ();
75
+ .buildProducerClient ();
76
76
```
77
77
78
78
### Prepare a batch of events
@@ -114,7 +114,7 @@ public class Sender {
114
114
// create a producer using the namespace connection string and event hub name
115
115
EventHubProducerClient producer = new EventHubClientBuilder ()
116
116
.connectionString(connectionString, eventHubName)
117
- .buildProducer ();
117
+ .buildProducerClient ();
118
118
119
119
// prepare a batch of events to send to the event hub
120
120
EventDataBatch batch = producer. createBatch();
@@ -155,54 +155,55 @@ The Java client library for Event Hubs is available for use in Maven projects fr
155
155
1 . Use the following code to create a new class called ` Receiver ` . Replace the placeholders with the values used when you created the event hub and storage account:
156
156
157
157
``` java
158
- import com.azure.messaging.eventhubs.* ;
159
- import com.azure.messaging.eventhubs.models.ErrorContext ;
160
- import com.azure.messaging.eventhubs.models.EventContext ;
161
- import java.util.concurrent.TimeUnit ;
162
- import java.util.function.Consumer ;
163
-
164
- public class Receiver {
165
-
166
- private static final String connectionString = " EVENT HUBS NAMESPACE CONNECTION STRING" ;
167
- private static final String eventHubName = " EVENT HUB NAME" ;
168
-
169
- public static void main (String [] args ) throws Exception {
170
-
171
- // function to process events
172
- Consumer<EventContext > processEvent = eventContext - > {
173
- System . out. print(" Received event: " );
174
- // print the body of the event
175
- System . out. println(eventContext. getEventData(). getBodyAsString());
176
- eventContext. updateCheckpoint();
177
- };
178
-
179
- // function to process errors
180
- Consumer<ErrorContext > processError = errorContext - > {
181
- // print the error message
182
- System . out. println(errorContext. getThrowable(). getMessage());
183
- };
184
-
185
- EventProcessorBuilder eventProcessorBuilder = new EventProcessorBuilder ()
186
- .consumerGroup(EventHubClientBuilder . DEFAULT_CONSUMER_GROUP_NAME )
187
- .connectionString(connectionString, eventHubName)
188
- .processEvent(processEvent)
189
- .processError(processError)
190
- .checkpointStore(new InMemoryCheckpointStore ());
191
-
192
- EventProcessorClient eventProcessorClient = eventProcessorClientBuilder. buildEventProcessorClient();
193
- System . out. println(" Starting event processor" );
194
- eventProcessorClient. start();
195
-
196
- System . out. println(" Press enter to stop." );
197
- System . in. read();
198
-
199
- System . out. println(" Stopping event processor" );
200
- eventProcessor. stop();
201
- System . out. println(" Event processor stopped." );
158
+ import com.azure.messaging.eventhubs.* ;
159
+ import com.azure.messaging.eventhubs.models.ErrorContext ;
160
+ import com.azure.messaging.eventhubs.models.EventContext ;
161
+ import java.util.concurrent.TimeUnit ;
162
+ import java.util.function.Consumer ;
202
163
203
- System . out. println(" Exiting process" );
204
- }
205
- }
164
+ public class Receiver {
165
+
166
+ final static String connectionString = " <EVENT HUBS NAMESPACE - CONNECTION STRING>" ;
167
+ final static String eventHubName = " <EVENT HUB NAME>" ;
168
+
169
+ public static void main (String [] args ) throws Exception {
170
+
171
+ // function to process events
172
+ Consumer<EventContext > processEvent = eventContext - > {
173
+ System . out. print(" Received event: " );
174
+ // print the body of the event
175
+ System . out. println(eventContext. getEventData(). getBodyAsString());
176
+ eventContext. updateCheckpoint();
177
+ };
178
+
179
+ // function to process errors
180
+ Consumer<ErrorContext > processError = errorContext - > {
181
+ // print the error message
182
+ System . out. println(errorContext. getThrowable(). getMessage());
183
+ };
184
+
185
+
186
+ EventProcessorClient eventProcessorClient = new EventProcessorClientBuilder ()
187
+ .connectionString(connectionString, eventHubName)
188
+ .processEvent(processEvent)
189
+ .processError(processError)
190
+ .consumerGroup(EventHubClientBuilder . DEFAULT_CONSUMER_GROUP_NAME )
191
+ .checkpointStore(new InMemoryCheckpointStore ())
192
+ .buildEventProcessorClient();
193
+
194
+ System . out. println(" Starting event processor" );
195
+ eventProcessorClient. start();
196
+
197
+ System . out. println(" Press enter to stop." );
198
+ System . in. read();
199
+
200
+ System . out. println(" Stopping event processor" );
201
+ eventProcessorClient. stop();
202
+ System . out. println(" Event processor stopped." );
203
+
204
+ System . out. println(" Exiting process" );
205
+ }
206
+ }
206
207
```
207
208
208
209
2. Download the ** InMemoryCheckpointStore . java** file from [GitHub ](https: // github.com/Azure/azure-sdk-for-java/tree/master/sdk/eventhubs/azure-messaging-eventhubs/src/samples/java/com/azure/messaging/eventhubs), and add it to your project.
0 commit comments