Предположим, вы используете Java, код ключа должен выглядеть следующим образом:
public static void main(String[] args)
throws EventHubException, IOException {
final ConnectionStringBuilder connStr = new ConnectionStringBuilder()
.setNamespaceName("----ServiceBusNamespaceName-----") // to target National clouds - use .setEndpoint(URI)
.setEventHubName("----EventHubName-----")
.setSasKeyName("-----SharedAccessSignatureKeyName-----")
.setSasKey("---SharedAccessSignatureKey----");
final Gson gson = new GsonBuilder().create();
final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(4);
final EventHubClient sender = EventHubClient.createFromConnectionStringSync(connStr.toString(), executorService);
try {
for (int batchNumber = 0; batchNumber < 10; batchNumber++) {
final EventDataBatch events = sender.createBatch();
EventData sendEvent;
// This do..while loop demonstrates - Maximizing batch size for every send call.
// sending multiple EventData's in one batch - guarantees order among the events sent in this batch
// and provides transactional semantics for the batch (all-or-none)
do {
final PayloadEvent payload = new PayloadEvent(100 + batchNumber);
final byte[] payloadBytes = gson.toJson(payload).getBytes(Charset.defaultCharset());
sendEvent = EventData.create(payloadBytes);
sendEvent.getProperties().put("from", "javaClient");
} while(events.tryAdd(sendEvent));
sender.sendSync(events);
System.out.println(String.format("Sent Batch - Batch Id: %s, Size: %s", batchNumber, events.getSize()));
}
} finally {
sender.closeSync();
executorService.shutdown();
}
}
Завершенный пример кода пакетной отправки для java равен здесь .