Skip to content
Merged
10 changes: 4 additions & 6 deletions sdk/eventhubs/azure-messaging-eventhubs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,12 @@ Both the asynchronous and synchronous Event Hub producer and consumer clients ca

The snippet below creates a synchronous Event Hub producer.

```java com.azure.messaging.eventhubs.eventhubproducerclient.construct
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
```java com.azure.messaging.eventhubs.eventhubproducerclient.connectionstring
String connectionString = "Endpoint={endpoint};SharedAccessKeyName={sharedAccessKeyName};"
+ "SharedAccessKey={sharedAccessKey};EntityPath={eventHubName}";

// "<<fully-qualified-namespace>>" will look similar to "{your-namespace}.servicebus.windows.net"
// "<<event-hub-name>>" will be the name of the Event Hub instance you created inside the Event Hubs namespace.
EventHubProducerClient producer = new EventHubClientBuilder()
.credential("<<fully-qualified-namespace>>", "<<event-hub-name>>",
credential)
.connectionString(connectionString)
.buildProducerClient();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ public void createProducer() {
// END: com.azure.messaging.eventhubs.eventhubproducerclient.construct
}

/**
* Code sample for creating a synchronous Event Hub producer using a connection string.
*/
public void createProducerWithConnectionString() {
// BEGIN: com.azure.messaging.eventhubs.eventhubproducerclient.connectionstring
String connectionString = "Endpoint={endpoint};SharedAccessKeyName={sharedAccessKeyName};"
+ "SharedAccessKey={sharedAccessKey};EntityPath={eventHubName}";

EventHubProducerClient producer = new EventHubClientBuilder()
.connectionString(connectionString)
.buildProducerClient();
// END: com.azure.messaging.eventhubs.eventhubproducerclient.connectionstring
}

/**
* Code sample for creating an async Event Hub producer.
*/
Expand Down
Loading