Updates for 3.0.0 RBAC release
This commit is contained in:
Родитель
3b3e3d74f1
Коммит
8370c39848
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="src" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>EventProcessorSample</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -47,12 +47,12 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs-eph</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
|
|
@ -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<Proxy> select(URI uri) {
|
||||
if (uri != null
|
||||
&& uri.getHost() != null
|
||||
&& uri.getHost().equalsIgnoreCase("youreventbushost.servicebus.windows.net")) {
|
||||
LinkedList<Proxy> 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<EventData> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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<EventHubClient>() {
|
||||
createSenders[count] = EventHubClient.createFromConnectionString(this.connectionString, executorService).thenAccept(new Consumer<EventHubClient>() {
|
||||
@Override
|
||||
public void accept(EventHubClient eventHubClient) {
|
||||
clients[clientsIndex] = eventHubClient;
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>azure-eventhubs</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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<EventHubClient>() {
|
||||
createSenders[count] = EventHubClient.createFromConnectionString(this.connectionString, executorService).thenAccept(new Consumer<EventHubClient>() {
|
||||
@Override
|
||||
public void accept(EventHubClient eventHubClient) {
|
||||
clients[clientsIndex] = eventHubClient;
|
||||
|
|
Загрузка…
Ссылка в новой задаче