diff --git a/eng/lintingconfigs/revapi/track2/revapi.json b/eng/lintingconfigs/revapi/track2/revapi.json
index 6a3743edf739..2575e95ad70c 100644
--- a/eng/lintingconfigs/revapi/track2/revapi.json
+++ b/eng/lintingconfigs/revapi/track2/revapi.json
@@ -328,6 +328,14 @@
"annotationType": "com\\.azure\\.cosmos\\.util\\.Beta",
"justification": "Cosmos SDK removes the Beta annotation to GA its APIs. Only Beta annotation removals are permitted; removal of any other annotation (Deprecated, Jackson, etc.) will still fail the build."
},
+ {
+ "code": "java.method.visibilityIncreased",
+ "old": {
+ "matcher": "regex",
+ "match": "method (void|reactor\\.core\\.publisher\\.Mono
+ * EventData event = new EventData("maple");
+ *
+ * producer.send(event)
+ * .subscribe(unused -> {
+ * },
+ * error -> System.err.println("Error occurred while sending event:" + error),
+ * () -> System.out.println("Send complete."));
+ *
+ *
+ *
* @param event Event to send to the service.
* @return A {@link Mono} that completes when the event is pushed to the service.
+ * @throws NullPointerException if {@code event} is {@code null}.
+ * @throws AmqpException if the size of {@code event} exceeds the maximum size of a single batch.
*/
- MonoSends a single event to the associated Event Hub with the send options. If the size of the single event + * exceeds the maximum size allowed, an exception will be triggered and the send will fail. For high throughput + * publishing scenarios, using {@link EventDataBatch} to publish events is recommended. Batches are created using + * {@link #createBatch()} and {@link #createBatch(CreateBatchOptions)}.
+ * + * + *
+ * EventData event = new EventData("Melbourne");
+ *
+ * SendOptions sendOptions = new SendOptions().setPartitionKey("cities");
+ * producer.send(event, sendOptions)
+ * .subscribe(unused -> {
+ * },
+ * error -> System.err.println("Error occurred while sending event:" + error),
+ * () -> System.out.println("Send complete."));
+ *
+ *
*
*
* For more information regarding the maximum event size allowed, see
@@ -422,8 +452,11 @@ Mono Sends a single event to the associated Event Hub. If the size of the single event exceeds the maximum size
+ * allowed, an exception will be triggered and the send will fail. For high throughput publishing, use
+ * {@link EventDataBatch} or the {@link #send(Iterable)} overload to publish more than one event in one call.
* For more information regarding the maximum event size allowed, see
@@ -284,15 +292,28 @@ public EventDataBatch createBatch(CreateBatchOptions options) {
* Sends a single event to the associated Event Hub with the send options. If the size of the single event
+ * exceeds the maximum size allowed, an exception will be triggered and the send will fail. For high throughput
+ * publishing, use {@link EventDataBatch} or the {@link #send(Iterable, SendOptions)} overload to publish more
+ * than one event in one call.
* For more information regarding the maximum event size allowed, see
@@ -302,9 +323,11 @@ void send(EventData event) {
*
* @param event Event to send to the service.
* @param options The set of options to consider when sending this event.
+ * @throws NullPointerException if {@code event} or {@code options} is {@code null}.
+ * @throws AmqpException if the size of {@code event} exceeds the maximum size of a single batch.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
- void send(EventData event, SendOptions options) {
+ public void send(EventData event, SendOptions options) {
producer.send(event, options).block();
}
diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/samples/java/com/azure/messaging/eventhubs/EventHubsJavaDocCodeSamples.java b/sdk/eventhubs/azure-messaging-eventhubs/src/samples/java/com/azure/messaging/eventhubs/EventHubsJavaDocCodeSamples.java
index 90cf77c4a1d4..4ba66a32c684 100644
--- a/sdk/eventhubs/azure-messaging-eventhubs/src/samples/java/com/azure/messaging/eventhubs/EventHubsJavaDocCodeSamples.java
+++ b/sdk/eventhubs/azure-messaging-eventhubs/src/samples/java/com/azure/messaging/eventhubs/EventHubsJavaDocCodeSamples.java
@@ -487,6 +487,42 @@ public void batchSizeLimitedAsync() {
// END: com.azure.messaging.eventhubs.eventhubasyncproducerclient.createBatch#CreateBatchOptions-int
}
+ /**
+ * Code snippet to demonstrate how to send a single event using
+ * {@link EventHubProducerAsyncClient#send(EventData)}.
+ */
+ public void sendSingleEventSampleAsync() {
+ final EventHubProducerAsyncClient producer = builder.buildAsyncProducerClient();
+ // BEGIN: com.azure.messaging.eventhubs.eventhubasyncproducerclient.send#EventData
+ EventData event = new EventData("maple");
+
+ producer.send(event)
+ .subscribe(unused -> {
+ },
+ error -> System.err.println("Error occurred while sending event:" + error),
+ () -> System.out.println("Send complete."));
+ // END: com.azure.messaging.eventhubs.eventhubasyncproducerclient.send#EventData
+ }
+
+ /**
+ * Code snippet to demonstrate how to send a single event using
+ * {@link EventHubProducerAsyncClient#send(EventData, SendOptions)}.
+ */
+ public void sendSingleEventWithPartitionKeySampleAsync() {
+ final EventHubProducerAsyncClient producer = builder.buildAsyncProducerClient();
+
+ // BEGIN: com.azure.messaging.eventhubs.eventhubasyncproducerclient.send#EventData-SendOptions
+ EventData event = new EventData("Melbourne");
+
+ SendOptions sendOptions = new SendOptions().setPartitionKey("cities");
+ producer.send(event, sendOptions)
+ .subscribe(unused -> {
+ },
+ error -> System.err.println("Error occurred while sending event:" + error),
+ () -> System.out.println("Send complete."));
+ // END: com.azure.messaging.eventhubs.eventhubasyncproducerclient.send#EventData-SendOptions
+ }
+
/**
* Code snippet to demonstrate how to send a list of events using
* {@link EventHubProducerAsyncClient#send(Iterable)}.
@@ -650,6 +686,31 @@ public void batchSizeLimited() {
// END: com.azure.messaging.eventhubs.eventhubproducerclient.createBatch#CreateBatchOptions-int
}
+ /**
+ * Code snippet to demonstrate how to send a single event using {@link EventHubProducerClient#send(EventData)}.
+ */
+ public void sendSingleEventSample() {
+ final EventHubProducerClient producer = builder.buildProducerClient();
+ // BEGIN: com.azure.messaging.eventhubs.eventhubproducerclient.send#EventData
+ EventData event = new EventData("maple");
+ producer.send(event);
+ // END: com.azure.messaging.eventhubs.eventhubproducerclient.send#EventData
+ }
+
+ /**
+ * Code snippet to demonstrate how to send a single event using
+ * {@link EventHubProducerClient#send(EventData, SendOptions)}.
+ */
+ public void sendSingleEventWithPartitionKeySample() {
+ final EventHubProducerClient producer = builder.buildProducerClient();
+ // BEGIN: com.azure.messaging.eventhubs.eventhubproducerclient.send#EventData-SendOptions
+ EventData event = new EventData("Melbourne");
+
+ SendOptions sendOptions = new SendOptions().setPartitionKey("cities");
+ producer.send(event, sendOptions);
+ // END: com.azure.messaging.eventhubs.eventhubproducerclient.send#EventData-SendOptions
+ }
+
/**
* Code snippet to demonstrate how to send a list of events using {@link EventHubProducerClient#send(Iterable)}.
*/
diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientTest.java
index 55d3f5a2c4d9..76c434dd77ac 100644
--- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientTest.java
+++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerAsyncClientTest.java
@@ -203,6 +203,28 @@ void teardown(TestInfo testInfo) {
messagesCaptor = null;
}
+ /**
+ * Verifies that a null event or null options results in a NullPointerException.
+ */
+ @Test
+ void sendSingleMessageNullArguments() {
+ // Arrange
+ final EventData testData = new EventData(TEST_CONTENTS.getBytes(UTF_8));
+
+ // Act & Assert
+ StepVerifier.create(producer.send((EventData) null))
+ .expectError(NullPointerException.class)
+ .verify(DEFAULT_TIMEOUT);
+
+ StepVerifier.create(producer.send((EventData) null, new SendOptions()))
+ .expectError(NullPointerException.class)
+ .verify(DEFAULT_TIMEOUT);
+
+ StepVerifier.create(producer.send(testData, null))
+ .expectError(NullPointerException.class)
+ .verify(DEFAULT_TIMEOUT);
+ }
+
/**
* Verifies that sending multiple events will result in calling producer.send(List<Message>).
*/
diff --git a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerClientTest.java b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerClientTest.java
index 396c08f18146..d9dfea0fd0b8 100644
--- a/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerClientTest.java
+++ b/sdk/eventhubs/azure-messaging-eventhubs/src/test/java/com/azure/messaging/eventhubs/EventHubProducerClientTest.java
@@ -172,6 +172,26 @@ public void sendSingleMessage() {
Assertions.assertEquals(Section.SectionType.Data, message.getBody().getType());
}
+ /**
+ * Verifies that a null event or null options throws a NullPointerException.
+ */
+ @Test
+ public void sendSingleMessageNullArguments() {
+ // Arrange
+ final EventHubProducerClient producer = new EventHubProducerClient(asyncProducer);
+ final EventData eventData = new EventData("hello-world".getBytes(UTF_8));
+
+ // Act & Assert
+ try {
+ Assertions.assertThrows(NullPointerException.class, () -> producer.send((EventData) null));
+ Assertions.assertThrows(NullPointerException.class,
+ () -> producer.send((EventData) null, new SendOptions()));
+ Assertions.assertThrows(NullPointerException.class, () -> producer.send(eventData, null));
+ } finally {
+ producer.close();
+ }
+ }
+
/**
*Verifies start and end span invoked when sending a single message.
*/
+ * EventData event = new EventData("maple");
+ * producer.send(event);
+ *
+ *
*
*
+ * EventData event = new EventData("Melbourne");
+ *
+ * SendOptions sendOptions = new SendOptions().setPartitionKey("cities");
+ * producer.send(event, sendOptions);
+ *
+ *
*
*