Azure / azure-event-hubs-go

Golang client library for Azure Event Hubs https://azure.microsoft.com/services/event-hubs
MIT License
88 stars 69 forks source link

FilePersister with empty directory throws file not found error #241

Open smartpcr opened 2 years ago

smartpcr commented 2 years ago

hub initialized with connectionString and filePersister

        ctx := context.Background()
    fp, err := persist.NewFilePersister(persistDir)
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }

        hub, err := eventhub.NewHubFromConnectionString(connStr, eventhub.HubWithOffsetPersistence(output))
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }
    defer hub.Close(ctx)

    runtimeInfo, err := hub.GetRuntimeInformation(ctx)
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }
    partitionIds := runtimeInfo.PartitionIDs
    consumerGroup := os.Getenv("EVENTHUB_CONSUMERGROUP")
    if consumerGroup == "" {
        consumerGroup = "$Default"
    }

    for _, partitionId := range partitionIds {
        _, err = hub.Receive(ctx, partitionId, output.HandleEvent, eventhub.ReceiveWithConsumerGroup(consumerGroup), eventhub.ReceiveWithPrefetchCount(20000))
        if err != nil {
            fmt.Println(err.Error())
            os.Exit(1)
        }
    }

Expected Behavior

should be able to create new file instead of throwing error

Actual Behavior

when file doesn't exist, it returns NewCheckpointFromStartOfStream(), err but err is not nil, and caused receive to fail here

Environment

jackjameshoward commented 2 years ago

@smartpcr Did you find a solution to this issue? Or how did you go about creating the file if it doesn't exist?