0

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)
milanbalazs
  • 4,811
  • 4
  • 23
  • 45
lucky man
  • 1
  • 1

1 Answers1

0

Here is your problem:

I/Choreographer: Skipped 382 frames! The application may be doing too much work on its main thread.

You can check this answer: The application may be doing too much work on its main thread

So you need to put your code to other thread. You can use AsyncTask, Threads, Handlers, Executors or a lot of other instruments. To check this just try

 new Thread(new Runnable() {
            @Override
            public void run() {
                //put your code here
            }
        }).start();

As to second problem with logger: if it will be exist in future add this to app gradle:

 implementation 'log4j:log4j:1.2.17'
 implementation 'de.mindpipe.android:android-logging-log4j:1.0.3'

Create logger class:

class Logger {
    static org.apache.log4j.Logger getLogger(Class clazz) {
        final LogConfigurator logConfigurator = new LogConfigurator();
        logConfigurator.setFileName(Environment.getExternalStorageDirectory().toString() + File.separator + "log/file.log");
        logConfigurator.setRootLevel(Level.ALL);
        logConfigurator.setLevel("org.apache", Level.ALL);
        logConfigurator.setUseFileAppender(true);
        logConfigurator.setFilePattern("%d %-5p [%c{2}]-[%L] %m%n");
        logConfigurator.setMaxFileSize(1024 * 1024 * 5);
        logConfigurator.setImmediateFlush(true);
        logConfigurator.configure();
        Logger log = Logger.getLogger(clazz);
        return log;
    }
}

And before creating azure client add this:

ALogger.getLogger("YOUR_CLASS_NAME".class);
  • Error position: final EventHubClient ehClient = EventHubClient.createSync(connStr.toString(), executorService); – lucky man Mar 02 '20 at 08:35
  • W/System.err: com.microsoft.azure.eventhubs.EventHubException: Operation not permitted W/System.err: at com.microsoft.azure.eventhubs.impl.ExceptionUtil.toException(ExceptionUtil.java:60) – lucky man Mar 02 '20 at 09:19
  • Have you added permission in manifest? Also, which connection protocol you are using and do you use proxy? – Ivan Ardelian Mar 02 '20 at 09:24
  • Added to AndroidManifest.xml but not work, not proxy. It only error in android. thereout run OK – lucky man Mar 02 '20 at 09:35
  • I have found ExeptionUtil class (https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core-amqp/src/main/java/com/azure/core/amqp/implementation/ExceptionUtil.java) and I think you have problem with arguments while creating ConnectionStringBuilder or EventHubClient. Try one more time, step by step with official documentation https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-java-get-started-send – Ivan Ardelian Mar 02 '20 at 10:01
  • This error only occurs on android, besides it is still OK. I think this error is due to android, I don't know the cause yet – lucky man Mar 02 '20 at 10:16
  • So on other platforms it works fine? In such case it can be caused by permissions. Also try to add in manifest – Ivan Ardelian Mar 02 '20 at 10:20
  • You still have error "The application may be doing too much work on its main thread." Or you need to put your code to separate thread or publish full class code and I'll fix it – Ivan Ardelian Mar 03 '20 at 08:27