Skip to content

Instantly share code, notes, and snippets.

@ronniegeraghty
Last active May 7, 2024 18:56
Show Gist options
  • Save ronniegeraghty/25022464b417a6cf3c3c961121647cc6 to your computer and use it in GitHub Desktop.
Save ronniegeraghty/25022464b417a6cf3c3c961121647cc6 to your computer and use it in GitHub Desktop.
Event Grid Namespaces Go Study Starter Files

Instructions for Starter Project set up

  1. Create a dir for the exercise.
  2. Within that dir create a eventSender and a eventReceiver dir.
  3. Within the eventSender dir run the following commands:
  • go mod init eventSender
  • go get github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/aznamespaces
  1. In the eventSender dir create a eventSender.go file and copy the contents of the envetSender.go file from this gist into it.
  2. Within the eventSender dir, use the following command to run the event sender program:
  • go run eventSender.go
  1. Within the eventReceiver dir run the following commands:
  • go mod init eventReceiver
  • go get github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/aznamespaces
  1. In the eventReceiver dir create a eventReceiver.go file and copy the contents of the eventReceiver.go file from this gist into it.
  2. Within the eventReceiver die, use the following command to run the event receiver program:
  • go run eventReceiver.go
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/aznamespaces"
)
// Azure Event Grid Namespace Details
var topicEndpoint = "https://eventgridnamespace-userstudy-egn.westus2-1.eventgrid.azure.net"
var topicKey = os.Getenv("EVENTGRIDNAMESPACE_TOPIC_ACCESS_KEY")
var topicName = "topic01"
var subscription = "subscription01"
type TestModel struct {
Name string
Age int
}
func main() {
// TASK: Create an Event Grid client (Copy from event sender)
// TASK: Get 5 events from Event Grid Namespaces and
// print out their data and lock token
//
// [Event Grid Namecspace Service] ----[event1, event2, event3, event4, event5]----> [Event Grid Client]
// TASK: Give up ownership of the events where Name = Bob.
// Then verify the events were released successfully.
//
// [Event Grid Client] ----[?something?]----> [Event Grid Namespace Service] ----
// ---[event{Name: Bob, Age: 30}]----> [Different Event Grid Client]
// TASK: Discard the events where Name = Denis.
// Then verify the events were rejected successfully.
//
// [Event Grid Client] ----[?something?]----> [Event Grid Namespace Service] ----
// ---[event{Name: Denis, Age: 46}]----> [Dead Letter Queue]
// TASK: Extend the locks for for all other events with the "employee_source" source, then accept them.
// Then verify the event locks were extended and the events were accepted successfully.
//
// [Event Grid Client] ----[?something?]----> [Event Grid Namespace Service]
}
package main
import (
"context"
"fmt"
"os"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/messaging"
"github.com/Azure/azure-sdk-for-go/sdk/messaging/eventgrid/aznamespaces"
)
// Azure Event Grid Namespace Details
var topicEndpoint = "https://eventgridnamespace-userstudy-egn.westus2-1.eventgrid.azure.net"
var topicKey = os.Getenv("EVENTGRIDNAMESPACE_TOPIC_ACCESS_KEY")
var topicName = "topic01"
var subscription = "subscription01"
type TestModel struct {
Name string
Age int
}
func main() {
// TASK: Create an Event Grid client
// TASK: Send a single event of the TestModel type (shown above) with the "employee_source" source.
// Set Name to "Bob" and Age to 30
//
// [Event Grid Client] ----[event{Name: Bob, Age: 30}]----> [Event Grid Namespace Service]
// TASK: Send a batch of 3 event of the TestModel type, with the "employee_source" source and with the following data:
// Name: Denis, Age: 46
// Name: Marco, Age: 50
// Name: Andrea, Age: 60
// [Event Grid Client] ----[event{Name: Denis, Age: 46}, event{Name: Marco, Age: 50}, event{Name: Andrea, Age:60}]--
// ----> [Event Grid Namespace Service]
// TASK: Send a single event of the TestModel type as binary data.
// It should have the source: "employee_source", Name: Sam and Age: 38
//
// [Event Grid Client] ----[event{00101101}]----> [Event Grid Namespace Service]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment