Code:
public void eventHubs() throws EventHubException, ExecutionException, InterruptedException, IOException {
final ConnectionStringBuilder connStr = new ConnectionStringBuilder()
.setNamespaceName("---value---")
.setEventHubName("---value---")
.setSasKeyName("---value---")
.setSasKey("---value---");
final Gson gson = new GsonBuilder().create();
// The Executor handles all asynchronous tasks and this is passed to the EventHubClient instance.
// This enables the user to segregate their thread pool based on the work load.
// This pool can then be shared across multiple EventHubClient instances.
// The following sample uses a single thread executor, as there is only one EventHubClient instance,
// handling different flavors of ingestion to Event Hubs here.
final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
// 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);
try {
String data = 0.259848484 + "|" + 0.99999999999 + "|" + "2019/20/18T15:30";
System.out.println(data);
byte[] payloadBytes = gson.toJson(data).getBytes(Charset.defaultCharset());
EventData sendEvent = EventData.create(payloadBytes);
ehClient.sendSync(sendEvent);
System.out.println(Instant.now() + ": Send Complete...");
System.out.println("Press Enter to stop.");
} finally {
ehClient.closeSync();
executorService.shutdown();
}
}
Error:
I/c.iy.event_hub: NativeAlloc concurrent copying GC freed 1143(135KB) AllocSpace objects, 1(20KB) LOS objects, 52% free, 1380KB/2916KB, paused 894us total 321.619ms D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0 I/Choreographer: Skipped 382 frames! The application may be doing too much work on its main thread. W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". W/System.err: SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. W/System.err: com.microsoft.azure.eventhubs.EventHubException: Operation not permitted at com.microsoft.azure.eventhubs.impl.ExceptionUtil.toException(ExceptionUtil.java:60) at com.microsoft.azure.eventhubs.impl.MessagingFactory.onConnectionError(MessagingFactory.java:253) at com.microsoft.azure.eventhubs.impl.ConnectionHandler.onTransportError(ConnectionHandler.java:178) at org.apache.qpid.proton.engine.BaseHandler.handle(BaseHandler.java:191) W/System.err: at org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:108) at org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:324) at org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:291) at com.microsoft.azure.eventhubs.impl.MessagingFactory$RunReactor.run(MessagingFactory.java:507) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919) I/Choreographer: Skipped 42 frames! The application may be doing too much work on its main thread. D/EGL_emulation: eglMakeCurrent: 0xf627eec0: ver 3 0 (tinfo 0xebbe5180) D/EGL_emulation: eglMakeCurrent: 0xf627eec0: ver 3 0 (tinfo 0xebbe5180)