TFS1165747 Separated samples and added readmes

This commit is contained in:
clemensv 2018-02-07 18:37:53 +01:00
Родитель 6cb099124b
Коммит 6baace2532
28 изменённых файлов: 784 добавлений и 78 удалений

42
.gitignore поставляемый
Просмотреть файл

@ -344,4 +344,44 @@ __pycache__/
*.btp.cs *.btp.cs
*.btm.cs *.btm.cs
*.odx.cs *.odx.cs
*.xsd.cs *.xsd.cs
# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar
#Java
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar
*.iml
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

Просмотреть файл

@ -0,0 +1,36 @@
# Receive events from Azure Event Hubs using Java
**Note**: This sample is available as a tutorial [here](https://docs.microsoft.com/azure/event-hubs/event-hubs-java-get-started-receive-eph).
The tutorial walks you through the consuming/receiving events from event hub. The sample uses Event Processor Host for consuming the events. Events in an event hub are distributed in various partitions to achieve parallelism while consuming. EPH simplifies processing events from event hub by managing persistent checkpoints and parallel receives.
To run the sample, you need to edit the [sample code](src/main/java/com/microsoft/azure/eventhubs/samples/eventprocessorsample/EventProcessorSample.java) and provide the following information:
```java
final String namespaceName = "----ServiceBusNamespaceName-----";
final String eventHubName = "----EventHubName-----";
final String sasKeyName = "-----SharedAccessSignatureKeyName-----";
final String sasKey = "---SharedAccessSignatureKey----";
final String storageAccountName = "---StorageAccountName----"
final String storageAccountKey = "---StorageAccountKey----";
```
## Prerequisites
Please refer to the [overview README](../../readme.md) for prerequisites and setting up the sample environment, including creating an Event Hubs cloud namespace and an Event Hub.
## Build and run
The sample can be built independently with
```bash
mvn clean package
```
and then run with (or just from VS Code or another Java IDE)
```bash
java -jar ./target/eventprocessorsample-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eventprocessorsample</groupId>
<version>1.0.0</version>
<artifactId>eventprocessorsample</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.eventhubs.samples.eventprocessorsample.EventProcessorSample</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs-eph</artifactId>
<version>0.15.0</version>
</dependency>
</dependencies>
</project>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Basic; package com.microsoft.azure.eventhubs.samples.eventprocessorsample;
/* /*
* Until the official release, there is no package distributed for EventProcessorHost, and hence no good * Until the official release, there is no package distributed for EventProcessorHost, and hence no good

Просмотреть файл

@ -0,0 +1,30 @@
# Receive events from Azure Event Hubs using Java
This sample shows how to receive events from a particular Event Hub partition based on a date-time offset. This is a lower-level API gesture that most applications will not use, but rather lean on the Event Processor Host to manage partition ownership and check-pointing. The [Event Processor Sample](../EventProcessorSample) shows this higher level functionality.
To run the sample, you need to edit the [sample code](src/main/java/com/microsoft/azure/eventhubs/samples/receivebydatetime/ReceiveByDateTime.java) and provide the following information:
```java
final String namespaceName = "----ServiceBusNamespaceName-----";
final String eventHubName = "----EventHubName-----";
final String sasKeyName = "-----SharedAccessSignatureKeyName-----";
final String sasKey = "---SharedAccessSignatureKey----";
```
## Prerequisites
Please refer to the [overview README](../../readme.md) for prerequisites and setting up the sample environment, including creating an Event Hubs cloud namespace and an Event Hub.
## Build and run
The sample can be built independently with
```bash
mvn clean package
```
and then run with (or just from VS Code or another Java IDE)
```bash
java -jar ./target/receivebydatetime-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -0,0 +1,53 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>receivebydatetime</groupId>
<version>1.0.0</version>
<artifactId>receiveusingoffset</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.eventhubs.samples.receivebydatetime.ReceiveByDateTime</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.0</version>
</dependency>
</dependencies>
</project>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Basic; package com.microsoft.azure.eventhubs.samples.receivebydatetime;
import com.microsoft.azure.eventhubs.ConnectionStringBuilder; import com.microsoft.azure.eventhubs.ConnectionStringBuilder;
import com.microsoft.azure.eventhubs.EventData; import com.microsoft.azure.eventhubs.EventData;

Просмотреть файл

@ -0,0 +1,30 @@
# Receive events from Azure Event Hubs using Java
This sample shows how to receive events from a particular Event Hub partition based on a n absolute offset. This is a lower-level API gesture that most applications will not use, but rather lean on the Event Processor Host to manage partition ownership and check-pointing. The [Event Processor Sample](../EventProcessorSample) shows this higher level functionality.
To run the sample, you need to edit the [sample code](src/main/java/com/microsoft/azure/eventhubs/samples/receiveusingoffset/ReceiveUsingOffset.java) and provide the following information:
```java
final String namespaceName = "----ServiceBusNamespaceName-----";
final String eventHubName = "----EventHubName-----";
final String sasKeyName = "-----SharedAccessSignatureKeyName-----";
final String sasKey = "---SharedAccessSignatureKey----";
```
## Prerequisites
Please refer to the [overview README](../../readme.md) for prerequisites and setting up the sample environment, including creating an Event Hubs cloud namespace and an Event Hub.
## Build and run
The sample can be built independently with
```bash
mvn clean package
```
and then run with (or just from VS Code or another Java IDE)
```bash
java -jar ./target/receiveusingoffset-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>receiveusingoffset</groupId>
<version>1.0.0</version>
<artifactId>receiveusingoffset</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.eventhubs.samples.receiveusingoffset.ReceiveUsingOffset</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs-eph</artifactId>
<version>0.15.0</version>
</dependency>
</dependencies>
</project>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Basic; package com.microsoft.azure.eventhubs.samples.receiveusingoffset;
import com.microsoft.azure.eventhubs.ConnectionStringBuilder; import com.microsoft.azure.eventhubs.ConnectionStringBuilder;
import com.microsoft.azure.eventhubs.EventData; import com.microsoft.azure.eventhubs.EventData;

Просмотреть файл

@ -0,0 +1,30 @@
# Send events to Azure Event Hubs using Java
The [Send events to Azure Event Hubs using Java](https://docs.microsoft.com/azure/event-hubs/event-hubs-java-get-started-send) tutorial walks you through ingesting into your event hub using Java with this code.
To run the sample, you need to edit the [sample code](src/main/java/com/microsoft/azure/eventhubs/samples/send/Send.java) and provide the following information:
```java
final String namespaceName = "----ServiceBusNamespaceName-----";
final String eventHubName = "----EventHubName-----";
final String sasKeyName = "-----SharedAccessSignatureKeyName-----";
final String sasKey = "---SharedAccessSignatureKey----";
```
## Prerequisites
Please refer to the [overview README](../../readme.md) for prerequisites and setting up the sample environment, including creating an Event Hubs cloud namespace and an Event Hub.
## Build and run
The sample can be built independently with
```bash
mvn clean package
```
and then run with (or just from VS Code or another Java IDE)
```bash
java -jar ./target/send-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>send</groupId>
<version>1.0.0</version>
<artifactId>send</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.eventhubs.samples.send.Send</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>[2.8.2,]</version>
</dependency>
</dependencies>
</project>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Basic; package com.microsoft.azure.eventhubs.samples.send;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;

Просмотреть файл

@ -0,0 +1,45 @@
# Send batch events to Azure Event Hubs using Java
The [Send events to Azure Event Hubs using Java](https://docs.microsoft.com/azure/event-hubs/event-hubs-java-get-started-send) tutorial walks you through ingesting into your event hub using Java with this code.
This sample differs from the basic tutorial in that it collects a set of events and sends them all at once in a single gesture:
``` Java
final LinkedList<EventData> events = new LinkedList<>();
for (int count = 1; count < 11; count++) {
final PayloadEvent payload = new PayloadEvent(count);
final byte[] payloadBytes = gson.toJson(payload).getBytes(Charset.defaultCharset());
final EventData sendEvent = new EventData(payloadBytes);
sendEvent.getProperties().put("from", "javaClient");
events.add(sendEvent);
}
sender.sendSync(events);
```
To run the sample, you need to edit the [sample code](src/main/java/com/microsoft/azure/eventhubs/samples/sendbatch/SendBatch.java) and provide the following information:
```java
final String namespaceName = "----ServiceBusNamespaceName-----";
final String eventHubName = "----EventHubName-----";
final String sasKeyName = "-----SharedAccessSignatureKeyName-----";
final String sasKey = "---SharedAccessSignatureKey----";
```
## Prerequisites
Please refer to the [overview README](../../readme.md) for prerequisites and setting up the sample environment, including creating an Event Hubs cloud namespace and an Event Hub.
## Build and run
The sample can be built independently with
```bash
mvn clean package
```
and then run with (or just from VS Code or another Java IDE)
```bash
java -jar ./target/sendbatch-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sendbatch</groupId>
<version>1.0.0</version>
<artifactId>sendbatch</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.eventhubs.samples.sendbatch.SendBatch</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>[2.8.2,]</version>
</dependency>
</dependencies>
</project>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Basic; package com.microsoft.azure.eventhubs.samples.sendbatch;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;

Просмотреть файл

@ -0,0 +1,23 @@
# Automatically scale up Event Hubs throughput units
The [Automatically scale up Azure Event Hubs throughput units](https://docs.microsoft.com/azure/event-hubs/event-hubs-auto-inflate) article discusses how an event hub can automatically adapt to high event flow rates. This sample illustrates this functionality with a Java sender that will produce enough events to trigger the auto-scale function to kick in.
The sample is interactive and will ask for a throughput unit threshold to hit and for an event hub connection string.
## Prerequisites
Please refer to the [overview README](../../readme.md) for prerequisites and setting up the sample environment, including creating an Event Hubs cloud namespace and an Event Hub.
## Build and run
The sample can be built independently with
```bash
mvn clean package
```
and then run with (or just from VS Code or another Java IDE)
```bash
java -jar ./target/autoscaleoningress-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -0,0 +1,53 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>autoscaleoningress</groupId>
<version>1.0.0</version>
<artifactId>autoscaleoningress</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.eventhubs.autoscaleoningress.AutoScaleOnIngress</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.0</version>
</dependency>
</dependencies>
</project>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Benchmarks; package com.microsoft.azure.eventhubs.samples.autoscaleoningress;
import com.microsoft.azure.eventhubs.EventData; import com.microsoft.azure.eventhubs.EventData;
import com.microsoft.azure.eventhubs.EventHubException; import com.microsoft.azure.eventhubs.EventHubException;
@ -34,7 +34,7 @@ public class AutoScaleOnIngress {
// number is supposed to help bring 2 down) // number is supposed to help bring 2 down)
// ********************************************************************* // *********************************************************************
System.out.println(); System.out.println();
System.out.print("Enter no. of Target ThroughPut's to hit the EventHub: "); System.out.print("Enter no. of Target Throughput Units to hit the EventHub: ");
final int tus = Integer.parseInt(System.console().readLine()); final int tus = Integer.parseInt(System.console().readLine());
final int EVENT_SIZE = 100; // 100 bytes <-- Change these knobs to determine target throughput final int EVENT_SIZE = 100; // 100 bytes <-- Change these knobs to determine target throughput

Просмотреть файл

@ -0,0 +1,63 @@
/*
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
package com.microsoft.azure.eventhubs.samples.autoscaleoningress;
import com.microsoft.azure.eventhubs.EventData;
import com.microsoft.azure.eventhubs.EventHubClient;
import com.microsoft.azure.eventhubs.EventHubException;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
public final class EventHubClientPool {
private final int poolSize;
private final String connectionString;
private final Object previouslySentLock = new Object();
private final EventHubClient[] clients;
private int previouslySent = 0;
EventHubClientPool(final int poolSize, final String connectionString) {
this.poolSize = poolSize;
this.connectionString = connectionString;
this.clients = new EventHubClient[this.poolSize];
}
public CompletableFuture<Void> initialize() throws IOException, EventHubException {
final CompletableFuture[] createSenders = new CompletableFuture[this.poolSize];
for (int count = 0; count < poolSize; count++) {
final int clientsIndex = count;
createSenders[count] = EventHubClient.createFromConnectionString(this.connectionString).thenAccept(new Consumer<EventHubClient>() {
@Override
public void accept(EventHubClient eventHubClient) {
clients[clientsIndex] = eventHubClient;
}
});
}
return CompletableFuture.allOf(createSenders);
}
public CompletableFuture<Void> send(Iterable<EventData> events) {
final int poolIndex;
synchronized (this.previouslySentLock) {
poolIndex = this.previouslySent++ % poolSize;
}
return clients[poolIndex].send(events);
}
public CompletableFuture<Void> close() {
final CompletableFuture[] closers = new CompletableFuture[this.poolSize];
for (int count = 0; count < poolSize; count++) {
closers[count] = this.clients[count].close();
}
return CompletableFuture.allOf(closers);
}
}

Просмотреть файл

@ -0,0 +1,30 @@
# Event Hubs throughput benchmark
Please review the sample code comments.
To run the sample, you need to edit the [sample code](src/main/java/com/microsoft/azure/eventhubs/samples/send/Send.java) and provide the following information:
```java
final String namespaceName = "----ServiceBusNamespaceName-----";
final String eventHubName = "----EventHubName-----";
final String sasKeyName = "-----SharedAccessSignatureKeyName-----";
final String sasKey = "---SharedAccessSignatureKey----";
```
## Prerequisites
Please refer to the [overview README](../../readme.md) for prerequisites and setting up the sample environment, including creating an Event Hubs cloud namespace and an Event Hub.
## Build and run
The sample can be built independently with
```bash
mvn clean package
```
and then run with (or just from VS Code or another Java IDE)
```bash
java -jar ./target/ingressbenchmark-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -0,0 +1,53 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ingressbenchmark</groupId>
<version>1.0.0</version>
<artifactId>ingressbenchmark</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.microsoft.azure.eventhubs.ingressbenchmark.IngressBenchmark</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs</artifactId>
<version>0.15.0</version>
</dependency>
</dependencies>
</project>

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Benchmarks; package com.microsoft.azure.eventhubs.samples.ingressbenchmark;
import com.microsoft.azure.eventhubs.EventData; import com.microsoft.azure.eventhubs.EventData;
import com.microsoft.azure.eventhubs.EventHubClient; import com.microsoft.azure.eventhubs.EventHubClient;

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) Microsoft. All rights reserved. * Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information. * Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/ */
package com.microsoft.azure.eventhubs.samples.Benchmarks; package com.microsoft.azure.eventhubs.samples.ingressbenchmark;
import com.microsoft.azure.eventhubs.ConnectionStringBuilder; import com.microsoft.azure.eventhubs.ConnectionStringBuilder;
import com.microsoft.azure.eventhubs.EventData; import com.microsoft.azure.eventhubs.EventData;
@ -19,7 +19,7 @@ import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
/* /*
* Performance BenchMark is specific to customers load pattern!! * Performance Benchmark is specific to customers load pattern!!
* *
* This sample is intended to highlight various variables available to tune latencies * This sample is intended to highlight various variables available to tune latencies
* *

Просмотреть файл

@ -3,41 +3,38 @@
Azure Event Hubs is a highly scalable data streaming platform and event ingestion service, capable of receiving and processing millions of events per second. The samples present here enables Java developers to easily ingest and process events from your event hub. Azure Event Hubs is a highly scalable data streaming platform and event ingestion service, capable of receiving and processing millions of events per second. The samples present here enables Java developers to easily ingest and process events from your event hub.
## Prerequisites ## Prerequisites
1. The samples here are built using Maven. If you plan to use Maven, you can [download Maven](https://maven.apache.org/download.cgi). [Install and configure Maven](https://maven.apache.org/install.html). The samples present here requires version > 3.3.9.
1. The samples depend on the Java JDK 1.8 and are built using Maven. You can [download Maven](https://maven.apache.org/download.cgi). [Install and configure Maven](https://maven.apache.org/install.html). The sample require Maven version > 3.3.9.
2. You need an Azure Subscription, if you do not have one - create a [free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio) before you begin 2. You need an Azure Subscription, if you do not have one - create a [free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio) before you begin
3. [An Event Hubs namespace and an event hub where you ingest the data](https://docs.microsoft.com/azure/event-hubs/event-hubs-create) 3. [An Event Hubs namespace and an event hub where you ingest the data](https://docs.microsoft.com/azure/event-hubs/event-hubs-create)
4. [A SAS key to access the event hub](https://docs.microsoft.com/azure/event-hubs/event-hubs-create#SAS) 4. [A SAS key to access the event hub](https://docs.microsoft.com/azure/event-hubs/event-hubs-create#SAS)
## Ingest events into event hub ### Sending events
The tutorial [here](https://docs.microsoft.com/azure/event-hubs/event-hubs-java-get-started-send) walks you for ingesting into your event hub using Java. Download the code from GitHub. Provide the following details in your sample [Send client](https://github.com/Azure/azure-event-hubs/blob/master/samples/Java/src/main/java/com/microsoft/azure/eventhubs/samples/Basic/Send.java)
```java * **Send** - The [Send](./Basic/Send) sample illustrates how to ingest events into your event hub.
final String namespaceName = "----ServiceBusNamespaceName-----"; * **SendBatch** - The [SendBatch](./Basic/SendBatch) sample illustrates how to ingest batches of events into your event hub.
final String eventHubName = "----EventHubName-----";
final String sasKeyName = "-----SharedAccessSignatureKeyName-----"; ### Processing events
final String sasKey = "---SharedAccessSignatureKey----";
``` * **ReceiveByDateTime** - The [ReceiveByDateTime](./Basic/ReceiveByDateTime) sample illustrates how to receive events from an event hub partition using a specific date-time offset.
* **ReceiveUsingOffset** - The [ReceiveUsingOffset](./Basic/ReceiveUsingOffset) sample illustrates how to receive events from an event hub partition using a specific data offset.
## Process events from event hub * **EventProcessorSample** - The [EventProcessorSample](./Basic/EventProcessorSample) sample illustrates how to receive events from an event hub using the event processor host, which provides automatic partition selection and fail-over across multiple concurrent receivers.
The tutorial here walks you through the consuming/receiving events from event hub. You can download the sample from GitHub. The sample uses Event Processor Host for consuming the events. Events in an event hub are distributed in various partitions to achieve parallelism while consuming. EPH simplifies processing events from event hub by managing persistent checkpoints and parallel receives. Provide the following details in your sample [EventProcessorHost client](https://github.com/Azure/azure-event-hubs/blob/master/samples/Java/src/main/java/com/microsoft/azure/eventhubs/samples/Basic/EventProcessorSample.java)
### Benchmarks
```java * **AutoScaleOnIngress** - The [AutoScaleOnIngress](./Benchmarks/AutoScaleOnIngress) sample illustrates how an event hub can automatically scale up on high loads. The sample will send events at a rate that just exceed the configured rate of an event hub, causing the event hub to scale up.
final String namespaceName = "----ServiceBusNamespaceName-----"; * **IngressBenchmark** - The [IngressBenchmark](./Benchmarks/IngressBenchmark) sample allows measuring the ingress rate.
final String eventHubName = "----EventHubName-----";
## Build and run
final String sasKeyName = "-----SharedAccessSignatureKeyName-----";
final String sasKey = "---SharedAccessSignatureKey----"; All samples can be built at once with
final String storageAccountName = "---StorageAccountName----" ```bash
final String storageAccountKey = "---StorageAccountKey----"; mvn clean package
```
## Running the sample
Do a maven clean compile from the location you have your samples in
``` java
cd azure-event-hubs/samples/Java/
mvn clean compile exec:java
``` ```
The samples are dropped into the respective sample's ./target subfolder. The build packages all dependencies into a single assembly so that you can execute them with:
```bash
java -jar ./target/{project}-1.0.0-jar-with-dependencies.jar
```

Просмотреть файл

@ -1,36 +1,33 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>azure-eventhubs-samples</artifactId> <modelVersion>4.0.0</modelVersion>
<name>azure-eventhubs-samples</name> <groupId>com.microsoft.azure</groupId>
<artifactId>azure-eventhubs-samples</artifactId>
<name>azure-eventhubs-samples</name>
<version>1.0.0</version>
<packaging>pom</packaging>
<dependencies> <properties>
<dependency> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<groupId>com.microsoft.azure</groupId> </properties>
<artifactId>azure-eventhubs-eph</artifactId> <build>
<version>0.15.0</version> <directory>${project.basedir}/target</directory>
</dependency> <outputDirectory>${project.build.directory}/classes</outputDirectory>
</dependencies> <finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/classes</testOutputDirectory>
<build> <sourceDirectory>${project.basedir}/src/</sourceDirectory>
<plugins> <testSourceDirectory>${project.basedir}/test/</testSourceDirectory>
<plugin> </build>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>
<groupId>com.microsoft.azure</groupId>
<version>1.0.0</version>
<modules>
<module>Basic/EventProcessorSample</module>
<module>Basic/ReceiveByDateTime</module>
<module>Basic/ReceiveUsingOffset</module>
<module>Basic/Send</module>
<module>Basic/SendBatch</module>
<module>Benchmarks/AutoScaleOnIngress</module>
<module>Benchmarks/IngressBenchmark</module>
</modules>
</project> </project>

Просмотреть файл

@ -1,3 +0,0 @@
# Receive events from Azure Event Hubs using Java
**Note**: This sample is available as a tutorial [here](https://docs.microsoft.com/azure/event-hubs/event-hubs-java-get-started-receive-eph).

Просмотреть файл

@ -1,3 +0,0 @@
# Send events to Azure Event Hubs using Java
**Note**: This sample is available as a tutorial [here](https://docs.microsoft.com/azure/event-hubs/event-hubs-java-get-started-send).