Skip to content

Commit 67909e2

Browse files
Merge pull request #290039 from yogeshmo/main
Updating Email Java SDK docs with operation status
2 parents f06c10b + 8948874 commit 67909e2

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

articles/communication-services/quickstarts/email/includes/send-email-java.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ try
231231
|| pollResponse.getStatus() == LongRunningOperationStatus.IN_PROGRESS)
232232
{
233233
pollResponse = poller.poll();
234-
System.out.println("Email send poller status: " + pollResponse.getStatus());
234+
// The operation ID can be retrieved as soon as .poll() is called on the poller
235+
System.out.println("Email send poller status: " + pollResponse.getStatus() + ", operation id: " + pollResponse.getValue().getId());
235236

236237
Thread.sleep(POLLER_WAIT_TIME.toMillis());
237238
timeElapsed = timeElapsed.plus(POLLER_WAIT_TIME);
@@ -262,21 +263,41 @@ catch (Exception exception)
262263
Calling `beginSend` on the async client returns a `PollerFlux` object to which you can subscribe. The callbacks defined in the subscribe method will be triggered once the email sending opertion is complete. **Note that the initial request to send an email will not be sent until a subscriber is set up.**
263264

264265
```java
266+
Duration MAIN_THREAD_WAIT_TIME = Duration.ofSeconds(30);
267+
268+
// ExecutorService to run the polling in a separate thread
269+
ExecutorService executorService = Executors.newSingleThreadExecutor();
270+
265271
PollerFlux<EmailSendResult, EmailSendResult> poller = emailAsyncClient.beginSend(emailMessage);
266-
// The initial request is sent out as soon as we subscribe the to PollerFlux object
267-
poller.subscribe(
272+
273+
executorService.submit(() -> {
274+
// The initial request is sent out as soon as we subscribe the to PollerFlux object
275+
poller.subscribe(
268276
response -> {
269277
if (response.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) {
270-
System.out.printf("Successfully sent the email (operation id: %s)", response.getValue().getId());
278+
System.out.printf("Successfully sent the email (operation id: %s)\n", response.getValue().getId());
271279
}
272280
else {
273-
System.out.println("Email send status: " + response.getStatus());
281+
// The operation ID can be retrieved as soon as the first response is recieved from the PollerFlux.
282+
System.out.println("Email send status: " + response.getStatus() + ", operation id: " + response.getValue().getId());
274283
}
275284
},
276285
error -> {
277286
System.out.println("Error occurred while sending email: " + error.getMessage());
278287
}
279-
);
288+
);
289+
});
290+
291+
// In a real application, you might have a mechanism to keep the main thread alive.
292+
// For this sample we will keep the main thread alive for 30 seconds to make sure the child thread has time to recieve the SUCCESSFULLY_COMPLETED status.
293+
try {
294+
Thread.sleep(MAIN_THREAD_WAIT_TIME.toMillis());
295+
} catch (InterruptedException e) {
296+
e.printStackTrace();
297+
}
298+
299+
executorService.shutdown();
300+
System.out.println("Main thread ends.");
280301
```
281302

282303
---

0 commit comments

Comments
 (0)