Skip to content

Commit 695be74

Browse files
authored
Merge pull request #14046 from izzyacademy/patch-3
Updating How to Send Event Synchronously
2 parents 5752d3a + 8da60db commit 695be74

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: timlt
88
ms.service: event-hubs
99
ms.workload: core
1010
ms.topic: article
11-
ms.date: 08/20/2018
11+
ms.date: 08/27/2018
1212
ms.author: shvija
1313

1414
---
@@ -32,13 +32,13 @@ The code in this tutorial is based on the [SimpleSend GitHub sample](https://git
3232

3333
## Send events to Event Hubs
3434

35-
The Java client library for Event Hubs is available for use in Maven projects from the [Maven Central Repository](https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22azure-eventhubs%22). You can reference this library using the following dependency declaration inside your Maven project file. The current version is 1.0.1:
35+
The Java client library for Event Hubs is available for use in Maven projects from the [Maven Central Repository](https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22azure-eventhubs%22). You can reference this library using the following dependency declaration inside your Maven project file. The current version is 1.0.2:
3636

3737
```xml
3838
<dependency>
3939
<groupId>com.microsoft.azure</groupId>
4040
<artifactId>azure-eventhubs</artifactId>
41-
<version>1.0.1</version>
41+
<version>1.0.2</version>
4242
</dependency>
4343
```
4444

@@ -71,6 +71,10 @@ public class SimpleSend {
7171

7272
public static void main(String[] args)
7373
throws EventHubException, ExecutionException, InterruptedException, IOException {
74+
75+
76+
}
77+
}
7478
```
7579

7680
### Construct connection string
@@ -102,6 +106,33 @@ ehClient.closeSync();
102106

103107
```
104108

109+
### How messages are routed to EventHub partitions
110+
111+
Before messages are retrieved by consumers, they have to be published to the partitions first by the publishers. When messages are published to event hub synchronously using the sendSync() method on the com.microsoft.azure.eventhubs.EventHubClient object, the message could be sent to a specific partition or distributed to all available partitions in a round-robin manner depending on whether the partition key is specified or not.
112+
113+
When a string representing the partition key is specified, the key will be hashed to determine which partition to send the event to.
114+
115+
When the partition key is not set, then messages will round-robined to all available partitions
116+
117+
```java
118+
// Serialize the event into bytes
119+
byte[] payloadBytes = gson.toJson(messagePayload).getBytes(Charset.defaultCharset());
120+
121+
// Use the bytes to construct an {@link EventData} object
122+
EventData sendEvent = EventData.create(payloadBytes);
123+
124+
// Transmits the event to event hub without a partition key
125+
// If a partition key is not set, then we will round-robin to all topic partitions
126+
eventHubClient.sendSync(sendEvent);
127+
128+
// the partitionKey will be hash'ed to determine the partitionId to send the eventData to.
129+
eventHubClient.sendSync(sendEvent, partitionKey);
130+
131+
// close the client at the end of your program
132+
eventHubClient.closeSync();
133+
134+
```
135+
105136
## Next steps
106137

107138
You can learn more about Event Hubs by visiting the following links:

0 commit comments

Comments
 (0)