diff --git a/samples/Java/Basic/AdvancedSendOptions/pom.xml b/samples/Java/Basic/AdvancedSendOptions/pom.xml index b0bde814..6b9c1d9c 100644 --- a/samples/Java/Basic/AdvancedSendOptions/pom.xml +++ b/samples/Java/Basic/AdvancedSendOptions/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 com.google.code.gson diff --git a/samples/Java/Basic/AdvancedSendOptions/src/main/java/com/microsoft/azure/eventhubs/samples/AdvancedSendOptions/AdvancedSendOptions.java b/samples/Java/Basic/AdvancedSendOptions/src/main/java/com/microsoft/azure/eventhubs/samples/AdvancedSendOptions/AdvancedSendOptions.java index 4d5fedc7..b7e6a77a 100644 --- a/samples/Java/Basic/AdvancedSendOptions/src/main/java/com/microsoft/azure/eventhubs/samples/AdvancedSendOptions/AdvancedSendOptions.java +++ b/samples/Java/Basic/AdvancedSendOptions/src/main/java/com/microsoft/azure/eventhubs/samples/AdvancedSendOptions/AdvancedSendOptions.java @@ -46,7 +46,7 @@ public class AdvancedSendOptions { // Each EventHubClient instance spins up a new TCP/SSL connection, which is expensive. // It is always a best practice to reuse these instances. The following sample shows the same. - final EventHubClient ehClient = EventHubClient.createSync(connStr.toString(), executorService); + final EventHubClient ehClient = EventHubClient.createFromConnectionStringSync(connStr.toString(), executorService); PartitionSender sender = null; try { diff --git a/samples/Java/Basic/EventProcessorSample/.classpath b/samples/Java/Basic/EventProcessorSample/.classpath deleted file mode 100644 index db2a016f..00000000 --- a/samples/Java/Basic/EventProcessorSample/.classpath +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/Java/Basic/EventProcessorSample/.project b/samples/Java/Basic/EventProcessorSample/.project deleted file mode 100644 index 03043695..00000000 --- a/samples/Java/Basic/EventProcessorSample/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - EventProcessorSample - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/samples/Java/Basic/EventProcessorSample/pom.xml b/samples/Java/Basic/EventProcessorSample/pom.xml index 7f8149c0..e34f13b7 100644 --- a/samples/Java/Basic/EventProcessorSample/pom.xml +++ b/samples/Java/Basic/EventProcessorSample/pom.xml @@ -47,12 +47,12 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 com.microsoft.azure azure-eventhubs-eph - 2.5.0 + 3.0.0 log4j diff --git a/samples/Java/Basic/EventProcessorSample/src/main/java/com/microsoft/azure/eventhubs/samples/eventprocessorsample/EventProcessorSample.java b/samples/Java/Basic/EventProcessorSample/src/main/java/com/microsoft/azure/eventhubs/samples/eventprocessorsample/EventProcessorSample.java index d46b88eb..18f57ace 100644 --- a/samples/Java/Basic/EventProcessorSample/src/main/java/com/microsoft/azure/eventhubs/samples/eventprocessorsample/EventProcessorSample.java +++ b/samples/Java/Basic/EventProcessorSample/src/main/java/com/microsoft/azure/eventhubs/samples/eventprocessorsample/EventProcessorSample.java @@ -12,6 +12,7 @@ import com.microsoft.azure.eventprocessorhost.EventProcessorOptions; import com.microsoft.azure.eventprocessorhost.ExceptionReceivedEventArgs; import com.microsoft.azure.eventprocessorhost.IEventProcessor; import com.microsoft.azure.eventprocessorhost.PartitionContext; +import com.microsoft.azure.eventprocessorhost.EventProcessorHost.EventProcessorHostBuilder; import java.util.concurrent.ExecutionException; import java.util.function.Consumer; @@ -43,16 +44,13 @@ public class EventProcessorSample .setSasKeyName(sasKeyName) .setSasKey(sasKey); - // Create the instance of EventProcessorHost using the most basic constructor. This constructor uses Azure Storage for + // Create the instance of EventProcessorHost using the builder. This sample uses Azure Storage for // persisting partition leases and checkpoints. The host name, which identifies the instance of EventProcessorHost, must be unique. // You can use a plain UUID, or use the createHostName utility method which appends a UUID to a supplied string. - EventProcessorHost host = new EventProcessorHost( - EventProcessorHost.createHostName(hostNamePrefix), - eventHubName, - consumerGroupName, - eventHubConnectionString.toString(), - storageConnectionString, - storageContainerName); + EventProcessorHost host = EventProcessorHostBuilder.newBuilder(EventProcessorHost.createHostName(hostNamePrefix), consumerGroupName) + .useAzureStorageCheckpointLeaseManager(storageConnectionString, storageContainerName, "") + .useEventHubConnectionString(eventHubConnectionString.toString(), eventHubName) + .build(); // Registering an event processor class with an instance of EventProcessorHost starts event processing. The host instance // obtains leases on some partitions of the Event Hub, possibly stealing some from other host instances, in a way that diff --git a/samples/Java/Basic/ReceiveByDateTime/pom.xml b/samples/Java/Basic/ReceiveByDateTime/pom.xml index 3108cd86..f81e8db5 100644 --- a/samples/Java/Basic/ReceiveByDateTime/pom.xml +++ b/samples/Java/Basic/ReceiveByDateTime/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 diff --git a/samples/Java/Basic/ReceiveByDateTime/src/main/java/com/microsoft/azure/eventhubs/samples/receivebydatetime/ReceiveByDateTime.java b/samples/Java/Basic/ReceiveByDateTime/src/main/java/com/microsoft/azure/eventhubs/samples/receivebydatetime/ReceiveByDateTime.java index bb73e1af..57f72ce6 100644 --- a/samples/Java/Basic/ReceiveByDateTime/src/main/java/com/microsoft/azure/eventhubs/samples/receivebydatetime/ReceiveByDateTime.java +++ b/samples/Java/Basic/ReceiveByDateTime/src/main/java/com/microsoft/azure/eventhubs/samples/receivebydatetime/ReceiveByDateTime.java @@ -31,7 +31,7 @@ public class ReceiveByDateTime { .setSasKey("---SharedAccessSignatureKey----"); final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4); - final EventHubClient ehClient = EventHubClient.createSync(connStr.toString(), executorService); + final EventHubClient ehClient = EventHubClient.createFromConnectionStringSync(connStr.toString(), executorService); final EventHubRuntimeInformation eventHubInfo = ehClient.getRuntimeInformation().get(); final String partitionId = eventHubInfo.getPartitionIds()[0]; // get first partition's id diff --git a/samples/Java/Basic/ReceiveUsingSequenceNumber/pom.xml b/samples/Java/Basic/ReceiveUsingSequenceNumber/pom.xml index 82e58334..81219103 100644 --- a/samples/Java/Basic/ReceiveUsingSequenceNumber/pom.xml +++ b/samples/Java/Basic/ReceiveUsingSequenceNumber/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 diff --git a/samples/Java/Basic/ReceiveUsingSequenceNumber/src/main/java/com/microsoft/azure/eventhubs/samples/receiveusingsequencenumber/ReceiveUsingSequenceNumber.java b/samples/Java/Basic/ReceiveUsingSequenceNumber/src/main/java/com/microsoft/azure/eventhubs/samples/receiveusingsequencenumber/ReceiveUsingSequenceNumber.java index 8027db35..77de83a5 100644 --- a/samples/Java/Basic/ReceiveUsingSequenceNumber/src/main/java/com/microsoft/azure/eventhubs/samples/receiveusingsequencenumber/ReceiveUsingSequenceNumber.java +++ b/samples/Java/Basic/ReceiveUsingSequenceNumber/src/main/java/com/microsoft/azure/eventhubs/samples/receiveusingsequencenumber/ReceiveUsingSequenceNumber.java @@ -30,7 +30,7 @@ public class ReceiveUsingSequenceNumber { .setSasKey("---SharedAccessSignatureKey----"); final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4); - final EventHubClient ehClient = EventHubClient.createSync(connStr.toString(), executorService); + final EventHubClient ehClient = EventHubClient.createFromConnectionStringSync(connStr.toString(), executorService); final EventHubRuntimeInformation eventHubInfo = ehClient.getRuntimeInformation().get(); final String partitionId = eventHubInfo.getPartitionIds()[0]; // get first partition's id diff --git a/samples/Java/Basic/SendBatch/pom.xml b/samples/Java/Basic/SendBatch/pom.xml index e4df26e6..03d8e3a6 100644 --- a/samples/Java/Basic/SendBatch/pom.xml +++ b/samples/Java/Basic/SendBatch/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 com.google.code.gson diff --git a/samples/Java/Basic/SendBatch/src/main/java/com/microsoft/azure/eventhubs/samples/sendbatch/SendBatch.java b/samples/Java/Basic/SendBatch/src/main/java/com/microsoft/azure/eventhubs/samples/sendbatch/SendBatch.java index 686eb4a2..899034ca 100644 --- a/samples/Java/Basic/SendBatch/src/main/java/com/microsoft/azure/eventhubs/samples/sendbatch/SendBatch.java +++ b/samples/Java/Basic/SendBatch/src/main/java/com/microsoft/azure/eventhubs/samples/sendbatch/SendBatch.java @@ -31,7 +31,7 @@ public class SendBatch { final Gson gson = new GsonBuilder().create(); final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4); - final EventHubClient sender = EventHubClient.createSync(connStr.toString(), executorService); + final EventHubClient sender = EventHubClient.createFromConnectionStringSync(connStr.toString(), executorService); try { for (int batchNumber = 0; batchNumber < 10; batchNumber++) { diff --git a/samples/Java/Basic/SimpleProxy/pom.xml b/samples/Java/Basic/SimpleProxy/pom.xml index baf58c6e..f6b02138 100644 --- a/samples/Java/Basic/SimpleProxy/pom.xml +++ b/samples/Java/Basic/SimpleProxy/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 com.google.code.gson diff --git a/samples/Java/Basic/SimpleProxy/src/main/java/com.microsoft.azure.eventhubs.samples.SimpleProxy/SimpleProxy.java b/samples/Java/Basic/SimpleProxy/src/main/java/com.microsoft.azure.eventhubs.samples.SimpleProxy/SimpleProxy.java deleted file mode 100644 index 83b9bf86..00000000 --- a/samples/Java/Basic/SimpleProxy/src/main/java/com.microsoft.azure.eventhubs.samples.SimpleProxy/SimpleProxy.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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.SimpleProxy; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.microsoft.azure.eventhubs.*; - -import java.io.IOException; -import java.net.*; -import java.nio.charset.Charset; -import java.time.Instant; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; - - -public class SimpleProxy { - - public static void main(String[] args) - throws EventHubException, ExecutionException, InterruptedException, IOException { - - String proxyIpAddressStr = "---proxyhostname---"; - int proxyPort = 3128; - - //set the ProxySelector API; which offers the flexibility to select Proxy Server based on the Target URI. - ProxySelector systemDefaultSelector = ProxySelector.getDefault(); - ProxySelector.setDefault(new ProxySelector() { - @Override - public List select(URI uri) { - if (uri != null - && uri.getHost() != null - && uri.getHost().equalsIgnoreCase("youreventbushost.servicebus.windows.net")) { - LinkedList proxies = new LinkedList<>(); - proxies.add(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIpAddressStr, proxyPort))); - return proxies; - } - - // preserve system default selector for the rest - return systemDefaultSelector.select(uri); - } - @Override - public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { - // trace and follow up on why proxy server is down - if (uri == null || sa == null || ioe == null) { - throw new IllegalArgumentException("Arguments can't be null."); - } - - systemDefaultSelector.connectFailed(uri, sa, ioe); - - } - }); - - // if the proxy being used, doesn't need any Authentication - "setting Authenticator" step may be omitted - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - if (this.getRequestorType() == RequestorType.PROXY - && this.getRequestingScheme().equalsIgnoreCase("basic") - && this.getRequestingHost().equals(proxyIpAddressStr) - && this.getRequestingPort() == proxyPort) { - return new PasswordAuthentication("userName", "password".toCharArray()); - } - - return super.getPasswordAuthentication(); - } - }); - - final ConnectionStringBuilder connStr = new ConnectionStringBuilder() - .setNamespaceName("----NamespaceName-----") // to target National clouds - use .setEndpoint(URI) - .setEventHubName("----EventHubName-----") - .setSasKeyName("-----SharedAccessSignatureKeyName-----") - .setSasKey("---SharedAccessSignatureKey---"); - - connStr.setTransportType(TransportType.AMQP_WEB_SOCKETS); - - final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4); - final EventHubClient ehClient = EventHubClient.createSync(connStr.toString(), executorService); - final Gson gson = new GsonBuilder().create(); - PartitionSender sender = null; - - //sending events - try { - - String payload = "Message " + Integer.toString(1); - byte[] payloadBytes = gson.toJson(payload).getBytes(Charset.defaultCharset()); - EventData sendEvent = EventData.create(payloadBytes); - - sender = ehClient.createPartitionSenderSync("1"); - sender.sendSync(sendEvent); - - System.out.println(Instant.now() + ": Send Complete..."); - - } - finally { - - } - - final EventHubRuntimeInformation eventHubInfo = ehClient.getRuntimeInformation().get(); - final String partitionId = eventHubInfo.getPartitionIds()[1]; // get first partition's id - - final PartitionReceiver receiver = ehClient.createEpochReceiverSync( - EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, - partitionId, - EventPosition.fromEnqueuedTime(Instant.EPOCH), - 2345); - - try { - Iterable receivedEvents = receiver.receiveSync(10); - - if (receivedEvents != null) { - for (final EventData receivedEvent : receivedEvents) { - if (receivedEvent.getBytes() != null) - System.out.println(String.format("Message Payload: %s", new String(receivedEvent.getBytes(), Charset.defaultCharset()))); - } - } - - } finally { - // cleaning up receivers is paramount; - // Quota limitation on maximum number of concurrent receivers per consumergroup per partition is 5 - receiver.close() - .thenComposeAsync(aVoid -> ehClient.close(), executorService) - .whenCompleteAsync((t, u) -> { - if (u != null) { - // wire-up this error to diagnostics infrastructure - System.out.println(String.format("closing failed with error: %s", u.toString())); - } - }, executorService).get(); - - executorService.shutdown(); - } - } -} diff --git a/samples/Java/Basic/SimpleSend/pom.xml b/samples/Java/Basic/SimpleSend/pom.xml index 3bdffea7..6045b76f 100644 --- a/samples/Java/Basic/SimpleSend/pom.xml +++ b/samples/Java/Basic/SimpleSend/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 com.google.code.gson diff --git a/samples/Java/Basic/SimpleSend/src/main/java/com/microsoft/azure/eventhubs/samples/SimpleSend/SimpleSend.java b/samples/Java/Basic/SimpleSend/src/main/java/com/microsoft/azure/eventhubs/samples/SimpleSend/SimpleSend.java index c4cccbb7..57908cd9 100644 --- a/samples/Java/Basic/SimpleSend/src/main/java/com/microsoft/azure/eventhubs/samples/SimpleSend/SimpleSend.java +++ b/samples/Java/Basic/SimpleSend/src/main/java/com/microsoft/azure/eventhubs/samples/SimpleSend/SimpleSend.java @@ -40,7 +40,7 @@ public class SimpleSend { // Each EventHubClient instance spins up a new TCP/SSL connection, which is expensive. // It is always a best practice to reuse these instances. The following sample shows this. - final EventHubClient ehClient = EventHubClient.createSync(connStr.toString(), executorService); + final EventHubClient ehClient = EventHubClient.createFromConnectionStringSync(connStr.toString(), executorService); try { for (int i = 0; i < 100; i++) { diff --git a/samples/Java/Benchmarks/AutoScaleOnIngress/pom.xml b/samples/Java/Benchmarks/AutoScaleOnIngress/pom.xml index 7c70ccad..cf856c45 100644 --- a/samples/Java/Benchmarks/AutoScaleOnIngress/pom.xml +++ b/samples/Java/Benchmarks/AutoScaleOnIngress/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 diff --git a/samples/Java/Benchmarks/AutoScaleOnIngress/src/main/java/com/microsoft/azure/eventhubs/samples/autoscaleoningress/EventHubClientPool.java b/samples/Java/Benchmarks/AutoScaleOnIngress/src/main/java/com/microsoft/azure/eventhubs/samples/autoscaleoningress/EventHubClientPool.java index e7871810..702123e1 100644 --- a/samples/Java/Benchmarks/AutoScaleOnIngress/src/main/java/com/microsoft/azure/eventhubs/samples/autoscaleoningress/EventHubClientPool.java +++ b/samples/Java/Benchmarks/AutoScaleOnIngress/src/main/java/com/microsoft/azure/eventhubs/samples/autoscaleoningress/EventHubClientPool.java @@ -34,7 +34,7 @@ public final class EventHubClientPool { final CompletableFuture[] createSenders = new CompletableFuture[this.poolSize]; for (int count = 0; count < poolSize; count++) { final int clientsIndex = count; - createSenders[count] = EventHubClient.create(this.connectionString, executorService).thenAccept(new Consumer() { + createSenders[count] = EventHubClient.createFromConnectionString(this.connectionString, executorService).thenAccept(new Consumer() { @Override public void accept(EventHubClient eventHubClient) { clients[clientsIndex] = eventHubClient; diff --git a/samples/Java/Benchmarks/IngressBenchmark/pom.xml b/samples/Java/Benchmarks/IngressBenchmark/pom.xml index 3d4d0491..07456532 100644 --- a/samples/Java/Benchmarks/IngressBenchmark/pom.xml +++ b/samples/Java/Benchmarks/IngressBenchmark/pom.xml @@ -47,7 +47,7 @@ com.microsoft.azure azure-eventhubs - 2.3.0 + 3.0.0 diff --git a/samples/Java/Benchmarks/IngressBenchmark/src/main/java/com/microsoft/azure/eventhubs/samples/ingressbenchmark/EventHubClientPool.java b/samples/Java/Benchmarks/IngressBenchmark/src/main/java/com/microsoft/azure/eventhubs/samples/ingressbenchmark/EventHubClientPool.java index b8a2dc12..8ec98807 100644 --- a/samples/Java/Benchmarks/IngressBenchmark/src/main/java/com/microsoft/azure/eventhubs/samples/ingressbenchmark/EventHubClientPool.java +++ b/samples/Java/Benchmarks/IngressBenchmark/src/main/java/com/microsoft/azure/eventhubs/samples/ingressbenchmark/EventHubClientPool.java @@ -34,7 +34,7 @@ public final class EventHubClientPool { final CompletableFuture[] createSenders = new CompletableFuture[this.poolSize]; for (int count = 0; count < poolSize; count++) { final int clientsIndex = count; - createSenders[count] = EventHubClient.create(this.connectionString, executorService).thenAccept(new Consumer() { + createSenders[count] = EventHubClient.createFromConnectionString(this.connectionString, executorService).thenAccept(new Consumer() { @Override public void accept(EventHubClient eventHubClient) { clients[clientsIndex] = eventHubClient;