получение azure eventhub не работает в linux

Я работаю над проектом, в котором я читаю события устройства из Azure IotHub. Я использовал код, представленный в link< /а> . Я использую весеннюю загрузку для своего проекта. Код отлично работал на моей машине с Windows, но когда я развернул код на своем сервере (машина с Linux), получение azure eventhub не работает. Я также попробовал код на локальной машине с Linux, и столкнулся с той же проблемой: приложения выдают следующую ошибку и не получают никаких новых событий. Я также включил порты 5671 и 9352.

    Error:
    "Operation not allowed after the com.microsoft.azure.servicebus.MessageReceiver instance is Closed."

    **Code**:
    public class ReceiveEventService {

    public void startListening() {
            EventHubClient client0 = receiveMessages("0");
            EventHubClient client1 = receiveMessages("1");
            try {
                log.info(this.getClass(), "startListening", "Started listening to azure");
                System.in.read();
                client0.closeSync();
                client1.closeSync();
                System.exit(0);
            } catch (ServiceBusException | IOException e) {
                log.error(this.getClass(), "error in azure startListening", e);
            }
        }

    private EventHubClient receiveMessages(final String partitionId) {
            EventHubClient client = null;
            try {
                client = EventHubClient.createFromConnectionStringSync(deviceEndPointString);
            } catch (Exception e) {
                log.error(this.getClass(), "receiveMessages - Failed to create client", e);
                 System.exit(1);
            }
            try {
    client.createReceiver(EventHubClient.DEFAULT_CONSUMER_GROUP_NAME, partitionId, Instant.now())
                        .thenAccept(new Consumer<PartitionReceiver>() {
                            public void accept(PartitionReceiver receiver) {
                                log.info(this.getClass(), "receiveMessages",
                                        " *Created receiver on partition " + partitionId);
                                try {
                                    while (true) {
                                        Iterable<EventData> receivedEvents = receiver.receive(100).get();
                                        int batchSize = 0;
                                        if (receivedEvents != null) {
                                            for (EventData receivedEvent : receivedEvents) {
                                                log.info(this.getClass(), "receiveMessages", "Device ID:"
                                                        + receivedEvent.getSystemProperties()
                                                                .get("iothub-connection-device-id")
                                                        + " offset:" + receivedEvent.getSystemProperties().getOffset()
                                                        + " EnqueueTime:"
                                                        + receivedEvent.getSystemProperties().getEnqueuedTime() + "SeqNo:"
                                                        + receivedEvent.getSystemProperties().getSequenceNumber());
                                                batchSize++;
                                            }
                                        }
                                        log.debug(this.getClass(), "receiveMessages:",
                                                "Partition " + partitionId + " ReceivedBatch size" + batchSize);
                                    }
                                } catch (Exception e) {
                                    log.error(this.getClass(), "receiveMessages-Failed to receive messages", e);
                                }
                            }
                        });

            } catch (Exception e) {
                log.error(this.getClass(), "receiveMessages-Failed to create receiver", e);
            }
            return client;
        }

    }

Зависимости в моем pom.xml приведены ниже.

<dependency>
            <groupId>com.microsoft.azure.sdk.iot</groupId>
            <artifactId>iot-service-client</artifactId>
            <version>1.3.19</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-eventhubs-eph</artifactId>
            <version>0.13.0</version>
        </dependency>

        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-eventhubs</artifactId>
            <version>0.13.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure.sdk.iot</groupId>
            <artifactId>iot-device-client</artifactId>
            <version>1.1.26</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-servicebus</artifactId>
            <version>0.9.7</version>
        </dependency>

Мой основной класс, как показано ниже. Мое выполнение кода отлично работает и в Linux, но только часть azure eventhub выдает ошибку и не работает.

@SpringBootApplication
public class AzureApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(AzureApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(AzureApplication.class);
    }

}

person Madhu    schedule 02.08.2017    source источник
comment
Какую службу Azure вы использовали для развертывания приложения весенней загрузки? Виртуальная машина Azure Linux или Azure WebApps для Linux?   -  person Peter Pan    schedule 03.08.2017
comment
@PeterPan Я использую виртуальную машину Azure Linux   -  person Madhu    schedule 03.08.2017


Ответы (1)


Я прокомментировал строки «client.closeSync()», и все стало отлично работать как на моей локальной машине с Linux, так и на виртуальной машине Azure (Linux). Я не уверен, что это правильный подход, но обходной путь, похоже, работает на данный момент.

`public void startListening() {
            EventHubClient client0 = receiveMessages("0");
            EventHubClient client1 = receiveMessages("1");
            try {
                log.info(this.getClass(), "startListening", "Started listening to azure");
               // System.in.read();
               // client0.closeSync();
               // client1.closeSync();
               // System.exit(0);
            } catch (Exception e) {
                log.error("error in azure startListening", e);
            }
        }`
person Madhu    schedule 03.08.2017