Skip to content

Commit 5b546fc

Browse files
committed
updated code
1 parent d905508 commit 5b546fc

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

articles/event-hubs/get-started-java-send-v2.md

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ This code creates a producer client object that's used to produce/send events to
7272
```java
7373
EventHubProducerClient producer = new EventHubClientBuilder()
7474
.connectionString(connectionString, eventHubName)
75-
.buildProducer();
75+
.buildProducerClient();
7676
```
7777

7878
### Prepare a batch of events
@@ -114,7 +114,7 @@ public class Sender {
114114
// create a producer using the namespace connection string and event hub name
115115
EventHubProducerClient producer = new EventHubClientBuilder()
116116
.connectionString(connectionString, eventHubName)
117-
.buildProducer();
117+
.buildProducerClient();
118118

119119
// prepare a batch of events to send to the event hub
120120
EventDataBatch batch = producer.createBatch();
@@ -155,54 +155,55 @@ The Java client library for Event Hubs is available for use in Maven projects fr
155155
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:
156156

157157
```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;
202163

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+
}
206207
```
207208

208209
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

Comments
 (0)