Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Start only works when sending and receiving Events, but doesn't work when just receiving #187

Open
lumichael24 opened this issue Aug 25, 2020 · 1 comment

Comments

@lumichael24
Copy link

lumichael24 commented Aug 25, 2020

Expected Behavior

From the quick start code, if we remove the lines:
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, os.Kill)
<-signalChan

the event hub handler should still receive events from the EventHub since the Receive function is blocking until there is a connection to the EventHub.

Actual Behavior

Removing those lines of code AND the line that sends a new string to the EventHub results in the EventHub being closed early and nothing being printed in the handler function. Is it the expected behavior/required to have the OS signal channel or something like time.Sleep for the connection to persist as well as the events be returned from the EventHub?

Full code attached below for reference

`

hub, err := eventhub.NewHubFromConnectionString(connStr)

if err != nil {
	fmt.Println(err)
	return
}

ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

//hub.Send(ctx, eventhub.NewEventFromString("hello a different sdfsdf"))
handler := func(c context.Context, event *eventhub.Event) error {
	fmt.Println(string(event.Data))
	return nil
}

// listen to each partition of the Event Hub
runtimeInfo, err := hub.GetRuntimeInformation(ctx)
if err != nil {
	fmt.Println(err)
	return
}

for _, partitionID := range runtimeInfo.PartitionIDs {
	//eventhub.ReceiveWithLatestOffset()
	listenerHandle, err := hub.Receive(ctx, partitionID, handler, eventhub.ReceiveWithConsumerGroup("$Default"))
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(listenerHandle.Err())
}

//time.Sleep(10 * time.Second)
/*
	// Wait for a signal to quit:
	signalChan := make(chan os.Signal, 1)
	signal.Notify(signalChan, os.Interrupt, os.Kill)
	<-signalChan*/`

Environment

  • OS: Windows 10 Enterprise
  • Go version: go1.14.6 windows/amd64
  • Version of Library: github.com/Azure/azure-event-hubs-go v1.3.1
@catalinaperalta
Copy link
Member

Hi! That's interesting, I'll look into this and get back to you. In the meantime, we have this other example for a consumer that only receives events: https://github.com/Azure/azure-event-hubs-go/blob/master/_examples/helloworld/consumer/main.go.

This is the link to the full project that demonstrates how to a producer sends messages and how the consumer receives them: https://github.com/Azure/azure-event-hubs-go/tree/master/_examples/helloworld.

Hopefully that helps for a quick start while I look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants